Tools to quickly navigate your file system
No matter you are working on a terminal or a GUI system, navigating to the desired folder takes pretty time especially when you are drilling through the deep folder hierarchies. Is there a way to open directories (or files) instantly with just a few keystrokes in a terminal or in a GUI system? Here we will introduce several ways to do that, including creating alias commands(Linux/Windows), using AutoJump(an advanced cd
command for Linux/Windows/MacOS) or Listary(an amazing tool for finding/opening files/folders instantly on Windows).
Fast terminal navigation
Manual method: use a lot of alias commands (This also works for Git bash on Windows)
If you have some commonly accessed directories, a simple way to navigate them quickly is creating a lot of alias (nickname for a command) commands for opening them. There are two types of aliases – temporary and permanent. Temporary aliases apply to only the current session, they will be lost when a terminal is closed.
For manual solutions, maybe the first idea comes into your head is using symbolic links. Alias commands are handier to use.
To create a temporary alias is simple, just run alias jwp='cd /opt/john/apps/wordpress/
, then typing jwp
will take you to /opt/john/apps/wordpress/
folder. To remove this alias, run unalias jwp
.
To add permanent aliases, you can add them in your ~/.bashrc
file, but a better way is adding them in a separate file generally called .bash_aliases
. To do that, append below content in ~/.bashrc
(probably the content has been contained in this file).
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
Now you can create aliases in ~/.bash_aliases
. Below is an example which has several alias to quickly opening commonly used folders.
alias jwp='cd /opt/john/apps/wordpress/' # jump to wordpress folder
alias jwpc='cd /opt/john/apps/wordpress/wp-content/'
alias jwpp='cd /opt/john/apps/wordpress/wp-content/plugins/'
When you open a terminal next time, you can open wordpress
folder with just three keystrokes:
~$ jwp
/opt/john/apps/wordpress$
Or if you want the aliases to take effect immediately, run . ~/.bash_aliases
or source ~/.bash_aliases
.
If you want to add a new alias later, you can use a command:
echo "alias jwpt='cd /opt/john/apps/wordpress/wp-content/themes/'" >> ~/.bash_aliases
Create aliases for Git bash on Windows
To configure aliases for Git bash on windows, It is the same as you are on Linux.
An example of
C://Users/john/.bashrc
on Windows:> alias jwp='cd /d/wordpress/' > alias jwpc='cd /d/wordpress/wp-content/' > alias jwpt='cd /d/wordpress/wp-content/themes/' > ``` > > Add a permanent alias in Git bash: > > ```shell > $ echo "alias jwpp='cd /d/wordpress/wp-content/plugins/'" > ~/.bashrc > > # To make the new added alias take effect immediately > $ . ~/.bashrc > # Use the alias > $ jwpp > /d/wordpress/wp-content/plugins > $ > ``` > **Note:** > > Depending your Git for Windows version, if it does not read `~/.bashrc` automatically in the next time you open Git bash, you can put content `~/.bash_profile` instead of `~/.bahsrc` or create `~/.bash_profile` with below content to make it reads `~/.bashrc`. > > ```shell > if [ -f ~/.bashrc ]; then . ~/.bashrc; fi > ``` > > > **Tips:** When creating an alias, it is recommended to use `which` command to check whether there is already an existing command with that name. > > ```shell > $ which dir > > alias dir='ls' > /bin/ls > ``` > > As you see, `which` command can also be used to show an alias. See [create and remove alias](https://linoxide.com/linux-how-to/create-remove-alias-linux/#:~:text=How%20to%20Create%20and%20Remove%20alias%20in%20Linux,command%20also%20applies%20only%20to%20current%20session.%20) for more operations about aliases. ### Automated method: AutoJump (an advanced `cd` command for Linux/Windows/MacOS) [AutoJump](https://github.com/wting/autojump) is a magic command line tool which allows you to jump in directories efficiently. According to its official description, it works by maintaining a database of the directories you use the most from the command line. Therefore, directories must be visited before you can use this tool to jump to. Here are some example using AutoJump: ```shell # Jump to a directory that contains content. $ j content # such as a directory: /opt/john/apps/wordpress/wp-content # Jump to a child directory of the current directory $ jc themes # such as a child dirctory: /opt/john/apps/wordpress/ # Open a file explorer window (Mac Finder, Windows Explorer, GNOME Nautilus, etc.) # to the directory instead. $ jo content # Open a file explorer to a child directory. $ jco themes
AutoJump uses fuzzy matching to find the target directory, but what will happen if there are two directories with the same part? Such as there are two directories, one is projects
and the other is programs
, which directory j p
will jump into?
AutoJump will assign paths different weight according to your access rate. The database may looks like:
30 /home/user/web/projects
10 /home/user/git/programs
So j p
would jump into /home/user/web/projects
. If you want to be more accurate, you can also pass multiple options. j g p
would jump into /home/user/git/programs
.
You can also use j -i
to increase or j -d
to decrease the weight of the current directory.
AutoJump requires Python, first install it before install AutoJump.
Fast Windows navigation: Listary
Listary is absolutely an revolutionary tool for finding and opening files instantly or directories on Windows. You can just type the name of the target file or folder when the front application is a file explorer or the home screen, the fist character keystroke would trigger Listary to prompt a menu listing the matching files/folders at the lower-right corner. Then you use up/down and enter key to select the desired item in the list, the selected file/folder will be opened for you.
You can also left-click an item for more operation options, like opening its folder (for a file) or sending it. Pretty handy, isn’t it?
Its installation is simple, just download and install it. And it is a tiny tool, just 3.4MB (v5.0).
Resources
- Create and remove alias
- Linux alias tips
- cd is wasting your life mentions AutoJump tool
- quickly navigation in command line provides a symbolic solution.