Using Fasd in Linux for Quick Access to Files & Directories

In this guide, we want to show you an ultimate guide for Using Fasd Command in Linux for Quick Access to Files and Directories. Most Linux users use various Linux commands to switch between files and directories from the command-line and they should modify the full path to some of the commands to access the files and directories. For this purpose, there is a command line utility that makes it easier to access files and directories which is the Fasd command. It is written in Shell and will help you to access your files much easier.

Now you can follow the rest of the article to install and use the Fasd command that can help you access your files much easier than other Linux Commands such as cd.

Ultimate Guide For Using Fasd in Linux for Quick Access to Files & Directories

To complete this guide, you must have access to your server as a root or non-root user with sudo privileges. For this purpose, you can visit the Orcacore website and check our initial server setup guides for Linux distros.

Step 1 – Install Fasd Command in Linux

The Fasd command utility is available in most Linux distros. You can easily use your Linux package manager to install it.

Install Fasd in Ubuntu / Debian

In Debian-based distros, first, run the system update and install the Fasd utility with the following command:

# sudo add-apt-repository ppa:aacebedo/fasd
# sudo apt update
# sudo apt install fasd

Install Fasd in Centos / RHEL / AlmaLinux / Rocky Linux

To install Fasd in Centos 7 and RHEL 7, you can use the commands below:

# sudo yum install epel-release
# sudo yum install fasd

For installing Fasd in Centos 8 and RHEL 8 and later like AlmaLinux 9, you can install Fasd from Snap Store or clone it from GitHub. Here we use Git to install the Fasd command:

# sudo dnf install git
# sudo git clone https://github.com/clvv/fasd.git
# cd fasd
# sudo make install

Enable Fasd Command in Linux

When your installation is completed, you must add the following line to your ~/.bashrc file to enable the Fasd:

vi ~/.bashrc
eval "$(fasd --init auto)"

When you are done, save and close the file. Then, source the file to apply the changes:

source ~/.bashrc

Step 2 – Fasd Aliases in Linux

At this point, we want to show you the Fasd aliases. The Fasd command uses the default aliases for accessing the files and directories. Here you can see a default Fasd aliases:

1) alias a='fasd -a'        # any

2) alias s='fasd -si'       # show, search, select

3) alias d='fasd -d'        # directory

4) alias f='fasd -f'        # file

5) alias sd='fasd -sid'     # interactive directory selection

6) alias sf='fasd -sif'     # interactive file selection

7) alias z='fasd_cd -d'     # cd, same functionality as j in autojump

8) alias zz='fasd_cd -d -i' # cd with interactive selection

As you can see, each of these aliases is used for doing a specific action.

Step 3 – Fasd Syntax Command

The following command syntax used for Fasd:

fasd [options] [query ...]

The Fasd command will keep a history of the frequently visited directories or opened files from the command line. It lists these paths based on their “frecency”. To understand it better, you can run the Fasd command in your desired directory and it will show the path results that you have used:

fasd

As you saw in the above step, Fasd uses default aliases. You can use the f alias, to list your files in your current directory:

f

The a alias will show you both files and directories:

a

The s alias will list both directories and files previously visited. Then, it will wait for you to choose one of the paths to display it to the terminal.

And the d alias will show you the directories:

d

Step 4- Quick Access Files and Directories with Fasd in Linux

As you saw, the alias a=’fasd -a’ can be used for showing both files and directories. This will help you to easily find your files and directories. For example:

a
Example Output
6          /
6          /root
6          /root/core/test/test.txt
6          /root/orca
12         /root/core
12         /root/fasd
15         /root/core/test
15         /root/orca/test

Step 5 – Quick Navigate To Directories with Fasd in Linux

The Fasd utility uses alias z=’fasd_cd -d’ for switching between directories.

For example, we want to navigate to our core directory with the command below:

z co

Then, from there, we navigate to our test directory:

z te

As you can see, you can use the first two words of your directory for quick navigation.

Also, you can navigate to the subdirectories with one command. For example:

z co te

This will switch us to our core directory and the subdirectory test directly.

Note: If you have multiple locations and files with the same name, Fasd will access the file with a greater score which you have visited the most.

As you can see, the Fasd command will help you to save time and access and list your files in an easier way.

For more options, you can use the Fasd help command:

fasd -h
Output
fasd [options] [query ...]
[f|a|s|d|z] [options] [query ...]
  options:
    -s         list paths with scores
    -l         list paths without scores
    -i         interactive mode
    -e <cmd>   set command to execute on the result file
    -b <name>  only use <name> backend
    -B <name>  add additional backend <name>
    -a         match files and directories
    -d         match directories only
    -f         match files only
    -r         match by rank only
    -t         match by recent access only
    -R         reverse listing order
    -h         show a brief help message
    -[0-9]     select the nth entry

fasd [-A|-D] [paths ...]
    -A    add paths
    -D    delete paths

Conclusion

At this point, you have learned to access your files and directories much easier by using the Fasd command in Linux. It has default aliases that can help you save time and you don’t need to type the full path of your directories in the command.

Hope you enjoy it. You may be interested in these articles:

Tail Command in Linux for Logs

Counting Files in a Linux Directory with Examples

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!