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.
저자 소개
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.
채널별 검색
오토메이션
기술, 팀, 인프라를 위한 IT 자동화 최신 동향
인공지능
고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
오리지널 쇼
엔터프라이즈 기술 분야의 제작자와 리더가 전하는 흥미로운 스토리
제품
- Red Hat Enterprise Linux
- Red Hat OpenShift Enterprise
- Red Hat Ansible Automation Platform
- 클라우드 서비스
- 모든 제품 보기
툴
체험, 구매 & 영업
커뮤니케이션
Red Hat 소개
Red Hat은 Linux, 클라우드, 컨테이너, 쿠버네티스 등을 포함한 글로벌 엔터프라이즈 오픈소스 솔루션 공급업체입니다. Red Hat은 코어 데이터센터에서 네트워크 엣지에 이르기까지 다양한 플랫폼과 환경에서 기업의 업무 편의성을 높여 주는 강화된 기능의 솔루션을 제공합니다.