How to jump between defined set of locations

I am constantly moving between fixed list of several directories on daily basis. Using cd can be tedious at times, so I defined shell function to quickly jump between defined set of directories.

Define j shell function using ~/bin/ file.

# Jump between defined set of directories
# Source: 

# bookmarks file

# jump function
function j {
  if [ "$1" -a -f "$bookmarks_file" ]; then
    directory=$(awk -F: "{if (\$1 ==\"$1\") print \$2}" $bookmarks_file)
    if [ "$directory" ]; then
      cd $(eval echo $directory)

Source created shell function inside ~/.bashrc configuration file.

$ echo "source ~/bin/" | tee -a ~/.bashrc

Create bookmarks file ~/.bookmarks.


Use j function to jump between defined set of directories.

$ j b

You can verify defined directory using the following command.

$ echo $(j blog;pwd)                                                                                                                                                                     

It is very simple yet handy solution.

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system. He is also open for new opportunities and challenges.