When you start learning GNU/Linux, you will find some useful commands like cat, head, tail, grep.
Those commands are quite useful indeed and you will use them for sure.
The real improvement in my opinion is when you start learning some more advanced commands, some of them not part of the default GNU toolkit.
Fuzzy finder. I use fzf
daily for different tasks. In particular I use it
to search code, that is not part of a specific folder.
Next image shows this in action. Show all the files that contain the words, user, access, and does not contain tests, vendor, _nodemodules modules and profiles :
Another interesting use case is combine it with rg
, so you can see which files have some word inside, and match some specific path.
For example running: rg login -c | fzf
will list all files that contain the
login
word. And then you can search by some specific paths.
JQ is command like JSON processor. It allows to navigate JSON structures easily with a custom language.
I personally use it together with curl
curl -s https://ws.smn.gob.ar/map_items/weather |\
jq '[ .[] | select(.weather.temp < 0) | {place: .name, temp: .weather.temp} ]'
The command from above will lists all places of Argentina where the temperature is lower than 0 celsius degrees.
I recommend you checking this article
to learn more about jq
written by Adam Gordon Bell. Who by the way has a great podcast called
CoRecursive.
Doug McIlroy, the inventor of Unix pipes and one of the founders of the Unix tradition, had this to say at the time [McIlroy78]:
(i) Make each program do one thing well. To do a new job, build afresh rather than complicate old programs by adding new features.
(ii) Expect the output of every program to become the input to another, as yet unknown, program. Don’t clutter output with extraneous information. Avoid stringently columnar or binary input formats. Don’t insist on interactive input.
xargs
is a crucial part of this puzzle. When you want to communicate two programs using pipes |
sometimes you need to change the order of arguments or add new ones.
I use xargs
combined in a git alias to fuzzy find branch names of a repo.
cof = !git for-each-ref --sort=-creatordate --format='%(refname:short)' refs/heads | fzf | xargs git checkout
Or with rofi
to pipe the command name selected by the launcher in a particular position.
If you are learning GNU/Linux, you definitely will want to learn about xargs sooner or later.
Grep is an essential tool to search for content inside files. I use rg
instead for several reasons.
rg
..gitignore
file.There are two modifiers that are quite interesting to use with rg
.
You can show previous and next lines around the word to search: rg -A 2 -B 3 user.settings
And as shown in the FZF section, you can use rg -c something
to find how many occurrences of something you find.
And finally. When you need to type complex command lines commands with several pipes you can use this handy command.
Press Ctrl X + Ctrl E
and you will be able to type your complex command in an
editor, so when the editor is closed, the command is executed.