Merge pull request #1525 from su-kaiyao/master

完成翻译 20140822 15 Practical Examples of 'cd' Command in Linux.md
This commit is contained in:
geekpi 2014-08-24 18:24:44 +08:00
commit b993b7e2e0
2 changed files with 173 additions and 170 deletions

View File

@ -1,170 +0,0 @@
[su-kaiyao]翻译中
15 Practical Examples of cd Command in Linux
================================================================================
In Linux **cd (Change Directory)** command is one of the most important and most widely used command for newbies as well as system administrators. For admins on a headless server, **cd** is the only way to navigate to a directory to check log, execute a program/application/script and for every other task. For newbie it is among those initial commands they make their hands dirty with.
![15 cd command examples in linux](http://www.tecmint.com/wp-content/uploads/2014/08/cd-command-in-linux.png)
15 cd command examples in linux
Thus, keeping in mind, we here bringing you **15** basic commands of **cd** using tricks and shortcuts to reduce your efforts on the terminal and save time by using these known tricks.
### Tutorial Details ###
- Command Name : cd
- Stands for : Change Directory
- Availability : All Linux Distribution
- Execute On : Command Line
- Permission : Access own directory or otherwise assigned.
- Level : Basic/Beginners
1. Change from current directory to /usr/local.
avi@tecmint:~$ cd /usr/local
avi@tecmint:/usr/local$
2. Change from current directory to /usr/local/lib using absolute path.
avi@tecmint:/usr/local$ cd /usr/local/lib
avi@tecmint:/usr/local/lib$
3. Change from current working directory to /usr/local/lib using relative path.
avi@tecmint:/usr/local$ cd lib
avi@tecmint:/usr/local/lib$
4. **(a)** Move one directory back from where you are now.
avi@tecmint:/usr/local/lib$ cd -
/usr/local
avi@tecmint:/usr/local$
4. **(b)** Change Current directory to parent directory.
avi@tecmint:/usr/local/lib$ cd ..
avi@tecmint:/usr/local$
5. Show last working directory from where we moved (use switch) as shown.
avi@tecmint:/usr/local$ cd --
/home/avi
6. Move two directory up from where you are now.
avi@tecmint:/usr/local$ cd ../ ../
avi@tecmint:/usr$
7. Move to users home directory from anywhere.
avi@tecmint:/usr/local$ cd ~
avi@tecmint:~$
or
avi@tecmint:/usr/local$ cd
avi@tecmint:~$
8. Change working directory to current working directory (seems no use of in General).
avi@tecmint:~/Downloads$ cd .
avi@tecmint:~/Downloads$
or
avi@tecmint:~/Downloads$ cd ./
avi@tecmint:~/Downloads$
9. Your present working Directory is “/usr/local/lib/python3.4/dist-packages/ ”, change it to “/home/avi/Desktop/ ”, in one line command, by moving up in the directory till / then using absolute path.
avi@tecmint:/usr/local/lib/python3.4/dist-packages$ cd ../../../../../home/avi/Desktop/
avi@tecmint:~/Desktop$
10. Change from current working directory to /var/www/html without typing in full using TAB.
avi@tecmint:/var/www$ cd /v<TAB>/w<TAB>/h<TAB>
avi@tecmint:/var/www/html$
11. Navigate from your current working directory to /etc/v__ _, Oops! You forgot the name of directory and not supposed to use TAB.
avi@tecmint:~$ cd /etc/v*
avi@tecmint:/etc/vbox$
**Note:** This will move to **vbox** only if there is only one directory starting with **v**. If more than one directory starting with **v** exist, and no more criteria is provided in command line, it will move to the first directory starting with **v**, alphabetically as their presence in standard dictionary.
12. You need to navigate to user **av** (not sure if it is avi or avt) home directory, without using **TAB**.
avi@tecmint:/etc$ cd /home/av?
avi@tecmint:~$
13. What are pushd and popd in Linux?
Pushd and popd are Linux commands in bash and certain other shell which saves current working directory location to memory and bring to the directory from memory as current working directory, respectively as well as changes directory.
avi@tecmint:~$ pushd /var/www/html
/var/www/html ~
avi@tecmint:/var/www/html$
The above command saves the current location to memory and changes to the requested directory. As soon as popd is fired, it fetch the saved directory location from memory and makes it current working directory.
avi@tecmint:/var/www/html$ popd
~
avi@tecmint:~$
14. Change to a directory containing white spaces.
avi@tecmint:~$ cd test\ tecmint/
avi@tecmint:~/test tecmint$
or
avi@tecmint:~$ cd 'test tecmint'
avi@tecmint:~/test tecmint$
or
avi@tecmint:~$ cd "test tecmint"/
avi@tecmint:~/test tecmint$
15. Change from current working directory to Downloads and list all its settings in one go.
avi@tecmint:/usr$ cd ~/Downloads && ls
.
service_locator_in.xls
sources.list
teamviewer_linux_x64.deb
tor-browser-linux64-3.6.3_en-US.tar.xz
.
...
This is our attempt, to make you aware of Linux Workings and executions in least possible words and with as much as user friendliness as it used to be before.
Thats all for now. Ill be here again with another interesting topic soon. Till then stay tuned and connected to Tecmint. Dont forget to provide us with your valuable feedback in the comments below.
--------------------------------------------------------------------------------
via: http://www.tecmint.com/cd-command-in-linux/
作者:[Avishek Kumar][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://www.tecmint.com/author/avishek/

View File

@ -0,0 +1,173 @@
15个关于Linuxcd命令的练习例子
===
在Linux中**cd改变目录**命令,是对新手和系统管理员来说,最重要最常用的命令。对管理无屏幕服务器的管理员,‘**cd**‘是引导进入目录,检查日志,执行程序/应用软件/脚本和其余每个任务的唯一方法。对新手来说,是他们必须自己动手学习的最初始命令
![15 cd command examples in linux](http://www.tecmint.com/wp-content/uploads/2014/08/cd-command-in-linux.png)
Linux中15个cd命令举例
所以,请用心,我们在这会带给你**15**个基础的‘**cd**‘命令,它们富有技巧和捷径,学会使用这些了解到的技巧,会大大减少你在终端上花费的努力和时间
### 课程细节 ###
- 命令名称cd
- 代表:切换目录
- 使用平台所有Linux发行版本
- 执行方式:命令行
- 权限:访问自己的目录或者其余指定目录
- 级别:基础/初学者
1. 从当前目录切换到/usr/local
avi@tecmint:~$ cd /usr/local
avi@tecmint:/usr/local$
2. 使用绝对路径,从当前目录切换到/usr/local/lib
avi@tecmint:/usr/local$ cd /usr/local/lib
avi@tecmint:/usr/local/lib$
3. 使用相对路径,从当前路径切换到/usr/local/lib
avi@tecmint:/usr/local$ cd lib
avi@tecmint:/usr/local/lib$
4. **a**切换当前目录到上级目录
  avi@tecmint:/usr/local/lib$ cd -
/usr/local
avi@tecmint:/usr/local$
4. **b**切换当前目录到上级目录
avi@tecmint:/usr/local/lib$ cd ..
avi@tecmint:/usr/local$
5. 显示我们最后一个离开的工作目录(使用‘-’选项)
avi@tecmint:/usr/local$ cd --
/home/avi
6. 从当前目录向上级返回两层
avi@tecmint:/usr/local$ cd ../ ../
avi@tecmint:/usr$
7. 从任何目录返回到用户home目录
avi@tecmint:/usr/local$ cd ~
avi@tecmint:~$
or
avi@tecmint:/usr/local$ cd
avi@tecmint:~$
8. 切换工作目录到当前工作目录(通常情况下看上去没啥用)
avi@tecmint:~/Downloads$ cd .
avi@tecmint:~/Downloads$
or
avi@tecmint:~/Downloads$ cd ./
avi@tecmint:~/Downloads$
9. 你当前目录是“/usr/local/lib/python3.4/dist-packages”现在要切换到“home/avi/Desktop/”,要求:一行命令,通过向上一直切换直到‘/’,然后使用绝对路径
  avi@tecmint:/usr/local/lib/python3.4/dist-packages$ cd ../../../../../home/avi/Desktop/
avi@tecmint:~/Desktop$
10. 从当前工作目录切换到/var/www/html要求不要将命令打完整使用TAB
avi@tecmint:/var/www$ cd /v<TAB>/w<TAB>/h<TAB>
avi@tecmint:/var/www/html$
11. 从当前目录切换到/etc/v__ _啊呀你竟然忘了目录的名字但是你又不想用TAB
avi@tecmint:~$ cd /etc/v*
avi@tecmint:/etc/vbox$
**请注意:**如果只有一个目录以‘**v**‘开头,这将会移动到‘**vbox**‘。如果有很多目录以‘**v**‘开头,而且命令行中没有提供更多的标准,这将会移动到第一个以‘**v**‘开头的目录(按照他们在标准字典里字母存在的顺序)
12. 你想切换到用户‘**av**不确定是avi还是avt目录不用**TAB**
avi@tecmint:/etc$ cd /home/av?
avi@tecmint:~$
13. Linux下的pushed和poped
Pushed和poped是Linux bash命令也是其他几个能够保存当前工作目录位置至内存并且从内存读取目录作为当前目录的脚本这些脚本也可以切换目录
  avi@tecmint:~$ pushd /var/www/html
/var/www/html ~
avi@tecmint:/var/www/html$
上面的命令保存当前目录到内存然后切换到要求的目录。一旦poped被执行它会从内存取出保存的目录位置作为当前目录
  avi@tecmint:/var/www/html$ popd
~
avi@tecmint:~$
14. 切换到带有空格的目录
  avi@tecmint:~$ cd test\ tecmint/
avi@tecmint:~/test tecmint$
or
avi@tecmint:~$ cd 'test tecmint'
avi@tecmint:~/test tecmint$
or
avi@tecmint:~$ cd "test tecmint"/
avi@tecmint:~/test tecmint$
15. 从当前目录切换到下载目录,然后列出它所包含的内容(使用一行命令)
  avi@tecmint:/usr$ cd ~/Downloads && ls
.
service_locator_in.xls
sources.list
teamviewer_linux_x64.deb
tor-browser-linux64-3.6.3_en-US.tar.xz
.
...
我们尝试使用最少的词句和一如既往的友好来让你了解Linux的工作和执行
这就是所有内容。我很快会带着另一个有趣的主题回来的。在此之前保持和Tecmint的联系别忘了在下面给我们提供你宝贵的反馈和评论
---
via: http://www.tecmint.com/cd-command-in-linux/
作者:[Avishek Kumar][a]
译者:[译者ID](https://github.com/译者ID)
校对:[su-kaiyao](https://github.com/su-kaiyao)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[a]:http://www.tecmint.com/author/avishek/