Fasd – A Commandline Tool That Offers Quick Access to Files and Directories
Fasd (pronounced as “fast“) is command-line productivity booster, a self-contained POSIX shell script which enables quick and more efficient access to files and directories.
It is inspired by tools such as autojump, and the name fasd was created from the default suggested aliases:
It has been tested on the following shells: bash, zsh, mksh, pdksh, dash, busybox ash, FreeBSD 9 /bin/sh and OpenBSD /bin/sh. It keeps track of files and directories you have accessed, so that you can quickly reference them in the command line.
In this article, we will show how to install and use fasd with a few examples in Linux.
How Does fasd Work?
Fasd simply ranks files and directories by “frecency” (word was first invented by Mozilla and used in Firefox, find out more from here) a combination of the words “frequency” and “recency“.
If you use primarily the shell via the terminal to navigate and launch applications, fasd can enable you do it more efficiently. It helps you to open files regardless of which directory you are in.
With simple key strings, fasd can find a “frecent” file or directory and open it with command you specify.
How to Install and Use Fasd in Linux Systems
Fasd can be installed using PPA on Ubuntu and its derivatives.
$ sudo add-apt-repository ppa:aacebedo/fasd $ sudo apt-get update $ sudo apt-get install fasd
On other Linux distributions, you can install it from source as shown.
$ git clone https://github.com/clvv/fasd.git $ cd fasd/ $ sudo make install
Once you have installed Fasd, add the following line to your
~/.bashrc to enable it:
eval "$(fasd --init auto)"
Then source the file like this.
$ source ~/.bashrc
Fasd ships with the following useful default aliases:
alias a='fasd -a' # any alias s='fasd -si' # show / search / select alias d='fasd -d' # directory alias f='fasd -f' # file alias sd='fasd -sid' # interactive directory selection alias sf='fasd -sif' # interactive file selection alias z='fasd_cd -d' # cd, same functionality as j in autojump alias zz='fasd_cd -d -i' # cd with interactive selection
Let’s look at a few usage examples; the following example will list any “frecent” files and directories:
To quickly search a file or directory you accessed previously, use the s alias:
To view all files you previously worked with that have the letters “vim”, you can use the
f alias as follows:
$ f vim
To quickly and interactively cd into a previously accessed directory using the
zz alias. Simply select the directory number from the first field (1-24 in the screenshot below):
You can add your own aliases in
~/.bashrc to fully utilize the power of fasd as in the examples below:
alias v='f -e vim' # quick opening files with vim alias m='f -e vlc' # quick opening files with vlc player
Then run the following command to source the file:
$ source ~/.bashrc
To open a file quickly named test.sh in vim, you would type:
$ v test.sh
We will cover one more example where you can use Fasd aliases with other commands:
$ f test $ cp `f test` ~/Desktop $ ls -l ~/Desktop/test.sh
For bash users, call _fasd_bash_hook_cmd_complete to make completion work. For example:
_fasd_bash_hook_cmd_complete v m j o
For more information, type:
$ man fasd
For additional customizations and usage examples, check out Fasd Github repository: https://github.com/clvv/fasd/
That’s all! In this article, we showed you how to install and use fasd in Linux. Do share with us info about similar tools you have come across out there, together with any other thoughts via the feedback section below.