pushd
and popd
The shell lets you "remember" which directories you have visited by adding them to a stack. A stack is like a stack of trays in a cafeteria. You can push a tray onto the top of the stack, or you can pop a tray off the top. The pushd
and popd
commands let you manipulate this stack of directories.
If you never use the pushd
and popd
commands, the shell's directory stack will only contain one entry: your current directory. Try it; go to your home directory by typing cd
and then look at the stack by typing:
dirs -l -v
(The -l option gives the full name for your home directory rather than a ~, and the -v option prints the stack one entry per line, numbered.)
You'll see something like this:
0 /home/student
Now type this:
cd /etc; dirs -l -v
You will see this:
0 /etc
Changing directories just replaces the top stack entry. Now, let's go back to your home directory and push it onto the stack:
pushd ~
The system will show you the stack again, all on one line, with the top entry at the left.
~ /etc
Typing dirs -l -v
will show it to you vertically and numbered:
0 /home/student 1 /etc
Read full article from CIT050: pushd and popd
No comments:
Post a Comment