上QQ阅读APP看书,第一时间看更新
How to do it...
The pushd and popd commands replace cd for changing your working directory.
- To push and change a directory to a path, use this command:
~ $ pushd /var/www
Now the stack contains /var/www ~ and the current directory is changed to /var/www.
- Now, push the next directory path:
/var/www $ pushd /usr/src
Now the stack contains /usr/src/var/www ~ and the current directory is /usr/src.
You can push as many directory paths as needed.
- View the stack contents:
$ dirs /usr/src /var/www ~ /usr/share /etc 0 1 2 3 4
- Now when you want to switch to any path in the list, number each path from 0 to n, then use the path number for which we need to switch. Consider this example:
$ pushd +3
Now it will rotate the stack and switch to the /usr/share directory.
pushd will always add paths to the stack. To remove paths from the stack, use popd.
- Remove a last pushed path and change to the next directory:
$ popd
Suppose the stack is /usr/src /var/www ~ /usr/share /etc, and the current directory is /usr/src. The popd command will change the stack to /var/www ~ /usr/share /etc and change the current directory to /var/www.
- To remove a specific path from the list, use popd +num. num is counted as 0 to n from left to right.