Command Line Tools for Faster File System Navigation

Command-line utilities to replace “cd command for faster file system navigation.

Photo by Hannah Joshua on Unsplash

Overview

In some of my previous articles, I walked through with you tools that could improve your development workflow. One of the command-line utilities is autojump which is a faster way to navigate the filesystem.

For developers, we mostly live within the terminal. Having a faster way to navigate the filesystem can definitely improve our productivity. In this article let’s explore the possible options we have.

Jumping Between Directories

Built-in Commands

Let’s start with some of the built-in commands.

  • alias: You can easily create alias for the most commonly used directories, e.g. your project folder
$ alias p="cd $HOME/projects"
  • Reverse/forward search: You can do a reverse search (Control-R), or forward search (Control-S) for the command history.
  • cd-: Use “cd-” to go back to the previous directory. You can also add a number to indicate how many folders you want to go back to, e.g. “cd-2
  • pushd, popd and dirs: Use pushd to save the current directory to the top of the directory stack and change the current directory to the folder. dirs to display the directory stack.popd to remove the top directory from the stack and navigates to the new top directory.

There are possibly more options than I listed above.

autojump

autojump is definitely one of the most popular options. autojump works by maintaining a database of the directories you use the most from the command line. Directories must be visited first before they can be jumped to.

Once installed,

  • j foo: Jump to a directory containing foo.
  • jc bar: Jump to a child directory.
  • jo music: Open file manager to a directory (instead of jumping).
  • jco images: Open file manager to a child directory.

autojump is available for Linux, macOS, and Windows.

z, zsh-z, and z.lua

z (jump around) is available for bash and zsh. It tracks your most used directories, based on ‘frecency’. After a short learning phase, z will take you to the most ‘frecent’ directory that matches all of the regexes given on the command line, in order.

Specifically for zsh, zsh-z is a native zsh port of z.

For example, z foo bar would match /foo/bar but not /bar/foo.

Frecency is a portmanteau of 'recent' and 'frequency'. It is a weighted rank that depends on how often and how recently something occurred

z.lua is an alternative to z with Windows and POSIX shells support and various improvements. It is also base on frecency just like z.

z.lua claims to be 10x times faster than fasd and autojump, 3x times faster than z. It is available for POSIX shells: bash, zsh, dash, sh, ash, ksh, busybox, and Fish Shell, Power Shell, and Windows cmd.

z foo       # cd to most frecent dir matching foo
z foo bar # cd to most frecent dir matching foo and bar
z -r foo # cd to the highest ranked dir matching foo
z -t foo # cd to most recently accessed dir matching foo
z -l foo # list matches instead of cd
z -c foo # restrict matches to subdirs of $PWD
z -e foo # echo the best match, don't cd
z -i foo # cd with interactive selection
z -I foo # cd with interactive selection using fzf
z -b foo # cd to the parent directory starting with foo

fasd

Fasd (pronounced similar to “fast”) is a command-line productivity booster. Fasd offers quick access to files and directories for POSIX shells. It is inspired by tools like autojump, z and v. Fasd keeps track of files and directories you have accessed so that you can quickly reference them in the command line.

Fasd comes with some useful aliases by default:

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

zoxide

zoxide (written in Rust) is a blazing fast replacement for your cd command, inspired by z and z.lua. It keeps track of the directories you use most frequently and uses a ranking algorithm to navigate to the best match.

z foo        # cd into highest ranked directory matching foo
z foo bar # cd into highest ranked directory matching foo and bar
z ~/foo # z also works like a regular cd command
z foo/ # cd into relative path
z .. # cd one level up
z - # cd into previous directory
zi foo # cd with interactive selection (using fzf)

zoxide integrates with fzf and there is also a plugin available for Vim/Neovim.

Jump

Jump integrates with your shell and learns about your navigational habits by keeping track of the directories you visit. It gives you the most visited directory for the shortest search term you type.

Similar to autojump, it introduces the j helper which can be bind to another letter.

$ j wc      # or...
$ j webc # or...
$ j console # or...
$ j b-c # or...

Terminal File Manager

Let’s explore the options we have for terminal file manager.

ranger

ranger is a console file manager with vi key bindings. This is one of the most popular options.

ranger
  • UTF-8 Support (if your Python copy supports it)
  • Multi-column display
  • Preview of the selected file/directory
  • Common file operations (create/chmod/copy/delete/…)
  • Renaming multiple files at once
  • VIM-like console and hotkeys
  • Automatically determine file types and run them with correct programs
  • Change the directory of your shell after exiting ranger
  • Tabs, bookmarks, mouse support.

nnn

nnn () is a full-featured terminal file manager. It's tiny and nearly 0-config with an incredible speed.

It is designed to be unobtrusive with smart workflows to match the trains of thought.

nnn can analyze disk usage, batch rename, launch apps, and pick files. The plugin repository has tons of plugins to extend the capabilities further e.g. preview, (un)mount disks, find & list, file/dir diff, upload files.

nnn

lf

lf (as in "list files") is a terminal file manager written in Go.

lf
  • Cross-platform (Linux, OSX, BSDs, Windows (partial))
  • Single binary without any runtime dependencies (except for terminfo database)
  • Fast startup and low memory footprint (due to native code and static binaries)
  • Server/client architecture to share file selection between multiple instances
  • Configuration with shell commands
  • Customizable keybindings (vi and readline defaults)
  • Preview filtering (for source highlight, archives, pdfs/images as text, etc.)

fff

fff (Fucking Fast File-Manager) is a simple file manager developed in bash.

  • It’s fast
  • Minimal (only requires bash and coreutils)
  • Smooth Scrolling (using vim keybindings)
  • Works on Linux, BSD, macOS, Haiku, etc.
  • Supports LS_COLORS!
  • File Operations (copy, paste, cut, ranger style bulk rename, etc)
  • Instant as you type search
  • Tab completion for all commands!
  • Automatic CD on exit (see setup)
  • Works as a file picker in Vim/Neovim (link)!
  • Display images with w3m-img!
  • Supports $CDPATH.

vifm

vifm (vi[m] like file manager) is a curses-based vi[m] like file manager extended with some useful ideas from mutt. If you use vi[m], vifm gives you complete keyboard control over your files without having to learn a new set of commands. It goes not just about vi[m] like keybindings, but also about modes, options, registers, commands, and other things you might already like in vi[m].

vifm

midnight commander

GNU Midnight Commander is a visual file manager. It is a feature-rich full-screen text mode application that allows you to copy, move and delete files and whole directory trees, search for files and run commands in the subshell. Internal viewer and editor are included.

Midnight Commander

Other Options — For Vim/Neovim Users

For Vim/Neovim users, instead of using the above command-line utilities, you can easily switch projects or folders using plugins.

Check out this article to see how to switch between multiple projects and folders easily from within Vim/Neovim.

Programmer and occasional blogger.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store