mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
commit
af29e78282
@ -1,91 +0,0 @@
|
||||
Advanced Directory Navigations Tips and Tricks in Linux
|
||||
================================================================================
|
||||
Directory navigation is one of the most basic concepts when it comes to understanding any command line system. Although it’s not a very difficult thing to understand when it comes to Linux, there are certain tips and tricks that can enhance your experience, and help you do things faster. In this article, we will discuss some advanced directory navigation tips.
|
||||
|
||||
### The Stuff We Already Know ###
|
||||
|
||||
Before jumping on to the advanced concepts, here is the basics of directory navigation that the article expects its readers to know:
|
||||
|
||||
- ‘pwd’ command is used to display the current working directory.
|
||||
- ‘cd’ command is used to change the current working directory.
|
||||
- ‘cd’ followed by space and followed by a couple of periods (cd ..) brings the control back to the parent directory
|
||||
- ‘cd’ followed by just the name of a subdirectory changes to that subdirectory
|
||||
- ‘cd’ followed by a complete path changes to that directory
|
||||
|
||||
### Advanced Tips ###
|
||||
|
||||
In this section we will discuss some directory navigation tips and tricks that will help you easily switch between directories.
|
||||
|
||||
### Change to the home directory from anywhere ###
|
||||
|
||||
Your home directory is an important directory, and everyone switches back and forth quite frequently. While typing ‘cd /home/<your-home-directory-name>’, isn’t a big deal, there is another way out which is not only easier but faster too. And that alternative is typing only ‘cd’.
|
||||
|
||||
Here is an example :
|
||||
|
||||
$ pwd
|
||||
/usr/include/netipx
|
||||
$ cd
|
||||
$ pwd
|
||||
/home/himanshu
|
||||
|
||||
So you can see, no matter where the current control is, just type ‘cd’ command and you can immediately change to your home directory.
|
||||
|
||||
**NOTE**- To change to the home directory of a particular user, just type ‘cd ~user_name'
|
||||
|
||||
### Switch between directories using cd - ###
|
||||
|
||||
Suppose your current working directory is this:
|
||||
|
||||
$ pwd
|
||||
/home/himanshu/practice
|
||||
|
||||
and you want to switch to the directory **/usr/bin/X11**, and then switch back to the directory mentioned above. So what will you do? The most straight forward way is :
|
||||
|
||||
$ cd /usr/bin/X11
|
||||
$ cd /home/himanshu/practice/
|
||||
|
||||
Although it seems a good way out, it really becomes tiring when the path to the directories is very long and complicated. In those cases, you can use the ‘cd -’ command.
|
||||
|
||||
While using ‘cd -’ command, the first step will remain the same, i.e., you have to do a cd <path> to the directory to you want to change to, but for coming back to the previous directory, just do a ‘cd -’, and that’s it.
|
||||
|
||||
$ cd /usr/bin/X11
|
||||
$ cd -
|
||||
/home/himanshu/practice
|
||||
$ pwd
|
||||
/home/himanshu/practice
|
||||
|
||||
And if you want to again go back to the last directory, which in this case is /usr/bin/X11, run the ‘cd -’ command again. So you can see that using ‘cd -’ you can switch between directories easily. The only limitation is that it works with the last switched directories only.
|
||||
|
||||
### Switch between directories using pushd and popd ###
|
||||
|
||||
![directory navigation](http://linoxide.com/wp-content/uploads/2014/06/pushd-popd.jpg)
|
||||
|
||||
If you closely analyse the ‘cd -’ trick, you’ll find that it helps switching between only the last two directories, but what if there is a situation in which you switch multiple directories, and then want to switch back to the first one. For example, if you switch from directory A to directory B, and then to directory C and directory D. Now, you want to change back to Directory A.
|
||||
|
||||
As a general solution, you can type ‘cd’ followed by the path to directory A. But then again, if the path is long or complicated, the process can be time-consuming, especially when you have to switch between them frequently.
|
||||
|
||||
In these kind of situations, you can use the ‘pushd’ and ‘popd’ commands. The ‘pushd’ command saves the path to a directory in memory, and the ‘popd’ command removes it, and switches back to it too.
|
||||
|
||||
For example :
|
||||
|
||||
$ pushd .
|
||||
/usr/include/netipx /usr/include/netipx
|
||||
$ cd /etc/hp/
|
||||
$ cd /home/himanshu/practice/
|
||||
$ cd /media/
|
||||
$ popd
|
||||
/usr/include/netipx
|
||||
$ pwd
|
||||
/usr/include/netipx
|
||||
|
||||
So you can see that I used ‘pushd’ command to save the path to current working directory (represented by .), and then changed multiple directories. To come back to the saved directory, I just executed the ‘popd’ command.
|
||||
|
||||
**NOTE**- You can also use ‘pushd’ command to switch back to the saved directory, but that doesn’t remove it from the memory, like ‘popd’ does.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://linoxide.com/linux-command/directory-navigations-tips-tricks/
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
@ -0,0 +1,94 @@
|
||||
Linux 高级目录导航技巧
|
||||
================================================================================
|
||||
|
||||
目录当行是命令行系统的基础概念.虽然不是什么难以理解的东西,但是知道一些技巧能够丰富你的经验并且提高工作效率.在这篇文章中,我们会讨论这些小技巧.
|
||||
|
||||
### 我们已经知道的东西 ###
|
||||
|
||||
在开始高级技巧之前,有一些必须知道的基本命令:
|
||||
|
||||
- ‘pwd’显示当前目录
|
||||
- ‘cd’ 改变当前目录
|
||||
- ‘cd’ 跟两个点(cd ..)能返回父目录
|
||||
- ‘cd’ 跟着相对目录就能直接切换当相对目录下
|
||||
- ‘cd’ 跟着绝对目录就能切换到绝对目录下
|
||||
|
||||
### 高阶技巧 ###
|
||||
|
||||
这节将介绍几个技巧方便你进行目录的切换
|
||||
|
||||
### 从任何地方回到home目录 ###
|
||||
|
||||
虽然使用‘cd /home/<your-home-directory-name>’, 不是什么大麻烦, 但是有一种方法直接打‘cd’ 就能回到home目录.
|
||||
|
||||
Here is an example :
|
||||
|
||||
$ pwd
|
||||
/usr/include/netipx
|
||||
$ cd
|
||||
$ pwd
|
||||
/home/himanshu
|
||||
|
||||
所以无论你在哪个目录下,都能这么干然后回到home目录.
|
||||
|
||||
**注意**- 如果要切换到确定用户的目录下, 就使用 ‘cd ~user_name'
|
||||
|
||||
### 用cd在目录间切换 - ###
|
||||
|
||||
假设你的工作目录是这样的:
|
||||
|
||||
$ pwd
|
||||
/home/himanshu/practice
|
||||
|
||||
如果你想切换到 **/usr/bin/X11**, 然后又想回到之前的目录. 你会怎么做? 最直接的 :
|
||||
|
||||
$ cd /usr/bin/X11
|
||||
$ cd /home/himanshu/practice/
|
||||
|
||||
虽然这样行得通,但是要记住这些复杂的目录是个大困难.这种情况下使用 ‘cd -’ 命令就行.
|
||||
|
||||
使用 ‘cd -’的第一步和上面的例子是一样的, 你可以 cd 到你想要切换到的<path>下 , 但是回到之前的目录用 ‘cd -’就可以.
|
||||
|
||||
$ cd /usr/bin/X11
|
||||
$ cd -
|
||||
/home/himanshu/practice
|
||||
$ pwd
|
||||
/home/himanshu/practice
|
||||
|
||||
如果你想回到最后访问的目录(在这个例子中是/usr/bin/X11),也使用'cd -'就可以.但是这个命令只会记住最后访问的目录,这是一个缺点.
|
||||
|
||||
### 用 pushd 和 popd 来切换目录 ###
|
||||
|
||||
![directory navigation](http://linoxide.com/wp-content/uploads/2014/06/pushd-popd.jpg)
|
||||
|
||||
|
||||
如果你对'cd -'非常了解了的话,你会发现这个命令只能帮助你在两个目录之间移动,但是很多场景下需要在很多目录之间切换.比如你要从A切换到B再到C然后又想回到A.
|
||||
|
||||
一般来说,你需要打出A的完整路劲,但是如果这个路径非常复杂,将是非常烦人的一件事,热别是你的切换非常频繁的话.
|
||||
|
||||
一些场景下可以使用 ‘pushd’ 还有 ‘popd’ 命令. The ‘pushd’ 将一个目录存到内存中,‘popd’ 将目录从内存中去除,并且转换到那个目录下.
|
||||
|
||||
例如 :
|
||||
|
||||
$ pushd .
|
||||
/usr/include/netipx /usr/include/netipx
|
||||
$ cd /etc/hp/
|
||||
$ cd /home/himanshu/practice/
|
||||
$ cd /media/
|
||||
$ popd
|
||||
/usr/include/netipx
|
||||
$ pwd
|
||||
/usr/include/netipx
|
||||
|
||||
使用‘pushd’ 命令存储当前的工作目录 (用 .表示), 然后切换到各种各样的目录去. 为了返回之前的目录 ,只要使用 ‘popd’命令就行了.
|
||||
使用
|
||||
|
||||
**注意**- 你也可以使用 ‘pushd’ 来切换到之前存储的目录, 但是不会像 ‘popd’ 一样去除这个目录.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://linoxide.com/linux-command/directory-navigations-tips-tricks/
|
||||
|
||||
译者:[ggaaooppeenngg](https://github.com/ggaaooppeenngg) 校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
Loading…
Reference in New Issue
Block a user