Changing Directories: pushd and popd

After you master the cd command, you need to learn to move around Unix using the pushd and popd commands. pushd <directoryname> will need to be entered if you want to specify the directory. With the popd command, however, you will not need to specify a directory name.

When changing between directories, these two commands allow you to make good use of the directory stack. The directory stack is a type of data storage that works as follows: Data is added to the top, thus creating the stack, and the most recently added “plate” of data is the first to be removed if requested, because it comes off the top of the stack. To describe this in terms of the pushd and popd commands, data is pushed (pushd) onto the stack and popped (popd) off the stack when requested by each command, thus making use of these commands quicker and more efficient than use of the cd command. The following examples will show you how to perform both pushd and popd:

> pwd
/
> cd /priv/home/rob
> pwd
/priv/home/rob

Or

> pwd
/priv/home/rob
> pushd /var/adm
/var/adm /priv/home/rob
> pwd
/var/adm

Then

> popd
/priv/home/rob
> pwd
/priv/home/rob

Try both commands and see which is easier and makes more sense for you. Either one will work just fine with your distribution of Unix.

You now know almost everything about navigating Unix and its supposedly cryptic file system. Let's expand this knowledge by taking a deeper look at paths, which were briefly discussed earlier in the lesson.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.199.27