피드 구독
Linux 

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: GitHub
  • fish 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.

Read full bio
UI_Icon-Red_Hat-Close-A-Black-RGB

채널별 검색

automation icon

오토메이션

기술, 팀, 인프라를 위한 IT 자동화 최신 동향

AI icon

인공지능

고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트

open hybrid cloud icon

오픈 하이브리드 클라우드

하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요

security icon

보안

환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보

edge icon

엣지 컴퓨팅

엣지에서의 운영을 단순화하는 플랫폼 업데이트

Infrastructure icon

인프라

세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보

application development icon

애플리케이션

복잡한 애플리케이션에 대한 솔루션 더 보기

Original series icon

오리지널 쇼

엔터프라이즈 기술 분야의 제작자와 리더가 전하는 흥미로운 스토리