1

Like everyone, I use the cd builtin command to navigate my directory-structure. Tab-completion comes in handy. Sometimes I use pushd and popd to jump between directories.

Some of those directories I use a lot. Is there a way to store them as a favorite, and then jump to that favorite by name?

I could easily shell-script this, and actually already did. But I want to know if there is a builtin, command or installable script for this.

I use bash 3.2 on macOS, but also bash 4.4 on Debian.

doekman
  • 259

2 Answers2

4

man bash:

   CDPATH The  search  path for the cd command.  This is a colon-separated
          list of directories in which the  shell  looks  for  destination
          directories  specified  by  the  cd  command.  A sample value is
          ".:~:/usr".
Ipor Sircer
  • 14,546
  • 1
  • 27
  • 39
3

This is not a favorites list, but a "parent of favorites" list: you can set the CDPATH bash shell variable to a list of directories you wish the shell to search when executing cd ....

For example, if you had directories

/home/doekman/work/projects/alpha
/home/doekman/work/projects/beta
/home/doekman/work/projects/gamma

Then, by setting CDPATH to ~/work/projects, you could switch to one of the subdirectories of projects with, e.g.

cd beta
user4556274
  • 8,995
  • 2
  • 33
  • 37