Almost a decade ago, I started to touch the command-line interface (CLI). I’m now a nerdy CLI lover and I’m so obsessed by its efficiency. Therefore, I’m always trying out new command-line commands. From time to time, some commands are replaced by other improved ones in my daily workflow. Especially for some frequently used commands, it’s worth to find better alternatives.
Here is a list of improved commands I’d like to share with you:
cd? z, up and fzf!
z
z is a very popular alternative command for jumping around. z
doesn’t require any additional configurations. Although it works out of the box, you need just a little bit of patience. Because z
has a “magic” algorithm based on “frequency” which can learn from the frequent vested directories after your cd
around for a while.
An easy and quick example how to z
:
|
|
Want to know how “frequency” score looks like for all directories? Simply run command z -l
will give you a list.
Want to clean some/all saved directories? Simply modify $HOME/.z
.
up
up is an interesting command to replace cd ..
and this ridicules one cd ../../../../
|
|
fzf
fzf is a versatile command, which can be combined in other commands. With the help of its amazing searchability, it can be used to “cd into the selected directory”:
ls? exa!
exa aims to be the modem replacement for ls
. In my opinion, it did it. exa is really easy to use. Its options are straightforward:
Here are my aliases:
|
|
More options to tweak exa: exa options
cat? bat!
bat is a cat
clone with syntax highlighting, line numbers and automatic paging (using less
as the default pager). To display the contents of a file using bat
looks like:
It’s possible to customize the theme of syntax highlighting. It supports Sublime Text syntax format. Check these default themes to have some inspirations: bat themes
grep? rg!
rg, ripgrep, is fast & furious. It has almost the same parameters of grep
command, with improved output style and speed.
One main usage of grep
for me is to find out which files contain some specific contents. An example to compare grep
and ripgrep
:
If you’re interested in how fast rg
can be? Check this comparison: rg vs. grep vs. ag. vs. ack… Not sure if it’s still the case now. But overall, ripgrep is fast enough for my daily use.
find? fd and fzf!
fd
fd is a replacement for find
focusing on user-friendly, with simplifying options of find
. For example, I want to edit a file but I don’t remember what’s its full path actually is. Usually, I need to find its full path first and then edit it:
|
|
Since I know the result will be only one file found, I can combine vi
inside find
command as well:
|
|
With fd
, the command is more readable:
|
|
fzf
fzf has an extremely powerful fuzzy searchability. It can nest finding steps directly with another command. I bind the key ctrl-t
to enable fzf. As the same example as above, but with fzf
, it’s a completely different story:
|
|
An alias to combine vim
and fzf
:
|
|
kill? fkill!
fkill, its f stands for “fabulously” (It’s definitely not the word I’m thinking in my mind 😉). Sometimes, kill
some zombie processes is necessary. fkill
can search a process and kill it interactively. It makes killing stylish:
watch? loop!
“UNIX’s missing loop command.” loop is designed to fill the gap. It works well to replace watch
:
|
|
Moreover, loop
has some awesome options to determine when to stop watching:
|
|
Example: stop watching when stop-now
file is created and then open it in vim:
|
|
Actually, using loop
to replace for
command is also promising and full of pleasure:
|
|
man? tldr, pet and how2!
tldr
tldr is a simplified collection of man pages. It returns some command snippets with practical examples:
pet
pet is a CLI snippet manager. It’s a handy tool to save some commands snippets which are easily forgotten. The idea is to use pet
building own reference manuals.
how2
how2 takes another approach to search for the right command: it queries questions and answers from stackoverflow!
In case the displayed answer is not what exactly you want, how2
provides the interactive mode to select in a list of all relative questions and answers.
From now on, we can get confident to “save the world”!
Share this list if you think it’s a good read for other CLI nerds. 💝
Drop me a message if you have other commands to recommend. ❤️