I’ve used a terminal daily for many years now. I use a heavily-customized, non-default shell. I make extensive use of tab completion and have memorized the flags for many commands. Until about a year ago, I thought I’d achieved the peak of terminal productivity. Then, I discovered a wave of shell utilities that, while obscure, fundamentally altered how I interact with my terminal environment for the better.
This article is the first in a series about these new utilities (plus a few tools I’ve known for longer, and love). Today, we will look at tools specifically for moving around your filesystem.
Jump around: z
You know how you can type the first few letters of a commonly-used website into your browser and hit Enter with the confidence that you’ll be taken to the right place? What if we brought that same experience into your shell? Imagine that you could teleport to a commonly-used directory just by typing a small part of its name. That’s what z
does.
The z
shell script keeps track of the directories that you visit and when you visited them. It combines the frequency of your access to a directory with the recency of your access to determine the "frecency" of your access. When you supply a couple of letters for the name of a directory, z
chooses the candidate containing the provided substring with the highest frecency. The result is correct an eerie amount of the time.
Here it is in action:
Quick Facts:
bash
/zsh
implementation: GitHubfish
implementation: GitHub- License (
bash
/zsh
): WTFPLv2 - License (
fish
): MIT - Language: Shell script
There are a number of similar tools out there, like autojump
and fasd
. Try them all!
Fuzzy find: fzf
Sometimes, searching for things with regular expressions is overkill. There are times when it should be enough for the right letters to occur in the right order. The fzf
utility lets you search for fuzzy matches painlessly. How does this tool relate to moving around your file system? Just wait and you’ll see.
By default, fzf
works on stdin, so you can use it like grep
:
$ fzf < long-log-file.txt
Live example:
Because fzf
works to filter stdin and sends the output on stdout, you can do much more than search files with this tool. Want to search for a directory beneath the current one?
$ fzf
That’s right. If stdin isn’t a pipe, fzf
searches all files below it and emits your choice on stdout, which makes it easy to combine the results with other commands like an editor.
If you’d like to achieve the same thing with more control, you could run:
$ find . -type d | fzf
You can use fzf
to move around by running:
$ cd $(find . -type d | fzf) #bash/zsh
$ cd (find . -type d | fzf) #fish
Now, there are other fun applications as well You can:
- Recall commands from your history with:
$ eval $(history | fzf) #bash/zsh $ eval (history | fzf) #fish
- Edit a file beneath the current directory with:
$ $EDITOR $(find . | fzf) #bash/zsh $ $EDITOR (find . | fzf) #fish
- Choose packages to install with:
$ sudo apt install $(apt search <word> 2>/dev/null | tail -n+3 | grep '^\w' | sed 's|([^/]+)/.*|\1|' | fzf) #bash/zsh $ sudo apt install (apt search <word> 2>/dev/null | tail -n+3 | grep '^\w' | string split / | fzf) #fish
- Make choices, in general, based on any line-delimited text. The sky is the limit!
The fzf
utility has existing integrations with bash
, zsh
, and fish
. If you install those shells, fzf
naturally augments and extends workflows like "reverse index search" and tab completion. I’m a heavy user of the fish
integration, myself.
Quick Facts:
- Get
fzf
: GitHub - License: MIT
- Language: Go
Want more?
If these tools look useful to you, stay tuned for more articles. If you can’t wait, this series is based on this talk that I gave at All Things Open 2019. You can find more tools and tricks there.
About the author
Chris works as an SRE for IBM. In his free time, he likes to hang out with his wife and cats, to read, and to hack on https://arbor.chat.
Browse by channel
Automation
The latest on IT automation for tech, teams, and environments
Artificial intelligence
Updates on the platforms that free customers to run AI workloads anywhere
Open hybrid cloud
Explore how we build a more flexible future with hybrid cloud
Security
The latest on how we reduce risks across environments and technologies
Edge computing
Updates on the platforms that simplify operations at the edge
Infrastructure
The latest on the world’s leading enterprise Linux platform
Applications
Inside our solutions to the toughest application challenges
Original shows
Entertaining stories from the makers and leaders in enterprise tech
Products
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Cloud services
- See all products
Tools
- Training and certification
- My account
- Customer support
- Developer resources
- Find a partner
- Red Hat Ecosystem Catalog
- Red Hat value calculator
- Documentation
Try, buy, & sell
Communicate
About Red Hat
We’re the world’s leading provider of enterprise open source solutions—including Linux, cloud, container, and Kubernetes. We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.
Select a language
Red Hat legal and privacy links
- About Red Hat
- Jobs
- Events
- Locations
- Contact Red Hat
- Red Hat Blog
- Diversity, equity, and inclusion
- Cool Stuff Store
- Red Hat Summit