pushd command, look! Cd more efficient than a content switching command

First blog, I had always wanted to write something to share!

Based on familiar you chiefs of various distributions (RedHat, Centos, Fedora) Linux kernel derived operating system, and certainly well aware of the cd command, know that it is used to change the directory today to introduce a similar to the cd command the wonderful pushd command, a directory to which the switching more efficient.

Different cd command pushd command

When the cd command to switch directories, can only be achieved step by step, if you switch in the same absolute path, you can use cd ./ cd ../ even cd ../../, such as:

The current directory is:

/home/user1/firstDir/secondDir/thirdDir

 And there are two folders in the current directory:

TestData
ResultData

If you now want to enter the next ResultData directory, you can do:

cd ./RestultData

If you do not enter ResultData directory and want to return to secondDir or firstDir directory, you can do:

cd ../  或者  cd ../../

If at this time you want to enter the absolute path to another directory (such as / usr / local / gdal221 / under lib), going from the root directory (/) to re-write from:

cd /usr/local/gdal221/lib

Then if they want to configure the operating system yum warehouse, then it would execute this command with cd:

cd /etc/yum.repos.d/

From the very beginning is located in the current directory / home / user1 / firstDir / secondDir / thirdDir when you want to switch to the / usr / local / gdal221 / lib directory, if the change is done with the pushd command to execute it, like this can :

pushd /usr/local/gdal221/lib

pushd command dirs -v command and usually used in combination, if performed at this time dirs -v command, see the following results:

dirs -v
0 /usr/local/gdal221/lib
1 /home/user1/firstDir/secondDir/thirdDir

Is currently in directory / usr / local / gdal221 / lib, if at this time to re-enter /etc/yum.repos.d/ yum repository configuration directory, then performed with pushd and dirs -v command, the results are as follows:

pushd /etc/yum.repos.d/
/etc/yum.repos.d/ /usr/local/gdal221/lib /home/user1/firstDir/secondDir/thirdDir
dirs -v
0 /etc/yum.repos.d/
1 /usr/local/gdal221/lib
2 /home/user1/firstDir/secondDir/thirdDir

Surely we will see here some understand the effect of using the pushd command to switch directories will be executed like a section of the directory path into a container to go inside, first performed at the bottom of the directory paths vessel, after execution before the top of the directory path will be placed in the path of the current working directory in which the entire path will be placed on top of the container. It is more efficient than the cd command, the following to say exactly what it is efficient place.

If you want to switch at this time to / home / user1 / firstDir / secondDir / thirdDir directory, use the pushd command can be executed just like this:

pushd +2
/home/user1/firstDir/secondDir/thirdDir /etc/yum.repos.d/ /usr/local/gdal221/lib

Which view the current working directory with the pwd command:

pwd
/home/user1/firstDir/secondDir/thirdDir

At the same time the implementation of dirs -v command to see the path of the vessel:

dirs -v 
0 /home/user1/firstDir/secondDir/thirdDir
1 /etc/yum.repos.d/
2 /usr/local/gdal221/lib

If at this time you want to enter the library directories gdal, then simply execute pushd plus in front of the path of the index number to:

pushd +2
/usr/local/gdal221/lib /home/user1/firstDir/secondDir/thirdDir /etc/yum.repos.d/

Dirs -v view the execution path of the container found gdal library catalog has been placed on top:

dirs -v
0 /usr/local/gdal221/lib
1 /home/user1/firstDir/secondDir/thirdDir
2 /etc/yum.repos.d/

At this point if you want to view the configuration of yum source, you can simply execute pushd +2.

See here you can find efficient compared to the cd command at the pushd command. pushd command is more appropriate to shift among several different working directory, work and study in the future, if there is demand for the same work, then use the pushd command also allows you to cope.

Released two original articles · won praise 0 · Views 106

Guess you like

Origin blog.csdn.net/maybcsdn/article/details/104852089