CLI: Creating and Navigating the Dirextory Stack

From: Alan Connor (zzzzzz_at_xxx.yyy)
Date: 07/12/05


Date: Tue, 12 Jul 2005 10:06:42 GMT

CLI = Command Line Interface (bash in this case)

Creating and Navigating the Directory Stack
-------------------------------------------

All of you know about changing directories with 'cd'.
Here's a much more effective way of negotiating the
directory tree on your linux box.

Create and navigate a directory stack (dirs) with a function
that calls pushd, and displays it with dirs.

Run these:

help pushd
help dirs

To make this easy, put the following functions abd
alias in your ~/.bashrc:

This one runs pushd and then ls -shF on the directory
it takes you to. It supersedes your normal cd:

cd()
{
    pushd "${@:-$HOME}" >/dev/null
    ls -shF
}

This one makes using the directory stack (dirs) very easy. First
hit "d" (see below) to bring up the directory stack, then enter
"c" followed by a space, followed by the number of the dir you
want to return to. (Read on, this will become clear.)

c ()
{
eval cd +${1}
}

alias d='dirs -v'

----------------------------------

Now have bash reread your ~/.bashrc with:

$ source ~/.bashrc # or '. ~/.bashrc' Same thing

Do:

d

Nothing there? That's because you haven't put any directories
in the stack with the above function "cd" that calls the pushd
command, which does a conventional cd and adds the new directory
to the stack.

Try this, starting in your home directory, entering "d -c" first,
to clear the stack:

cd /etc
cd /bin
cd /
cd /usr

Now do

d

to display the directory stack. It will look like this:

0 /usr
1 /
2 /bin
3 /etc
4 ~

That's your directory stack now. Suppose that you want
to return to /bin without typing 'cd /bin and without
losing track of where you've been? Do:

c 2

It doesn't seem like much with the above short stack,
and short directory names and paths, but if you are 6
levels deep in a directory and you want to return to
another directory you were at a while ago that is 5
levels deep in a different directory, and you can't
quite remember where that file was, then it makes ALL
the difference in the world.

Take the small amount of time it takes to set up and
learn the above, and you will find yourself in much
more control of your navigations around your directory
tree. And you will begin to understand why the CLI
makes the GUI look like the child's playpen it is.

AC

-- 
If you are posting through google for any purpose
other than learning to use a real newsreader,
many of us will not answer your questions.
  ----  news.software.readers  ----