Home > bash > stop frustration: navigate among directories in command line easily

stop frustration: navigate among directories in command line easily

Doing file manipulations in plain command line is a pain. That’s why I use Midnight Commander for tasks like copying, deleting, etc. But I’m still in pain :) If there are more than two directories that I want to work with, then even in MC I need to browse a lot and pass time with changing directories. Help!

I started to use two utilities that are very helpful. I found both of them in this thread.

(1) acd_func.sh
This script was originally published in a Linux Gazette article in 2004. It’s available here.

Simply download the script and add these lines to your ~/.bashrc:

# http://linuxgazette.net/109/misc/marinov/acd_func.html
source ~/bin/acd_func.sh
alias l="cd --"

“This is a scripts which defines a CD replacement function in order to keep, display and access history of visited directories. Normally the script will be sourced at the end of .bashrc.

cd —

Shows the history list of visited directories. The list shows the most recently visited names on the top.

This command is also assigned to ctrl+w.

cd -NUM

Changes the current directory with the one at position NUM in the history list. The directory is also moved from this position to the top of the list.” (source)

Since we need to use the command “cd --” a lot, I put a shorter alias on it called “l“, which stands for “list”.

This script is great but it has a drawback. It’s local in your current terminal. So if you open a new terminal and call the “cd --” command, the list is empty. I also wanted a global solution, that maintains a list among several terminal windows too. And this is how I found:

(2) autojump
Here is a nice blog post about it that I don’t want to quote completely just its abstract:

“autojump is a self-learning directory changer for navigating your filesystem. It works by maintaining a database of the directories you use the most from the command line. As soon as it’s installed it’ll start saving you time. Making easy to switch to the directories that are most important to you.” (source)

Install the package “autojump” and add these lines to the end of your ~/.bashrc:

# autojump
# http://www.thinkingmedia.ca/2014/10/how-to-install-autojump-on-ubuntu-14/
source /usr/share/autojump/autojump.bash

The official wiki is here.

Good to know:

  • To see the content of its database, use the command “j -s” (or “j --stat“).
  • TAB-completion is supported.
  1. October 18, 2015 at 22:55
    • October 18, 2015 at 23:38

      Give more info. Why is it better? How is it different?

  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: