The purpose of Unix commands are simple: provide a uniform I/O interface that can be composed with existing commands via piping. In this post, I’m going to highlight a few of my favorite non-standard shell commands and provide links to download them.
z - jump around
My favorite tool listed here.
z
is a simple application that builds up a history of all the directories you’ve visited.
When you want to change to a directory, you simple type z dirName
and the program will cd to the fully-resolved path.
For example:
➜ Files pwd
/Users/brycesmith/Files
➜ Files z downloads
➜ Downloads
In my experience, z
does a good job choosing the appropriate directory to change to, even if don’t fully spell out the name or if there are many duplicates.
z -e
will echo the directory instead of cd
to it, which is very useful when performing process substitution
View z
on GitHub
fd
fd
is a lot like find
, but with colorized output, more intuitive options and some neat bells and whistles.
In addition to globbing, I particularly enjoy that the tool supports regex with only single-quotes; no special option needed.
For example:
➜ unix_shell_commands git:(main) ✗ fd '[\w]+.md'
index.md
An example of fd’s colorized output
View fd
on GitHub
bat
This is a replacement for cat
.
In some ways, bat
works more like less
; text of sufficient length is opened in a view.
But bat
has the I/O behavior of cat
, so piping works as expected.
➜ Downloads bat robots.txt
│ File: robots.txt
1 │ # https://www.robotstxt.org/robotstxt.html
2 │ User-agent: *
3 │ Disallow:
➜ Downloads bat robots.txt > hey
Like fd
, bat
also colorizes its output:
Once again, you can find bat on GitHub.
rg
While ripgrep
and grep
probably deserve their own post, this tool is worth mentioning.
ripgrep
recursively applies regex to files in a given directory.
ripgrep
is fast.
It’s actually the search backend used by Visual Studio Code.
Similar to grep -r, but more succinct.
Example on a C++ project:
➜ project4 git:(master) ✗ rg '[\w]+<' | head -10
List_test_iterator.cpp: List<double> li;
List_test_iterator.cpp: List<double>::Iterator it = li.begin(); //using standard assignment behavior
List_test_iterator.cpp: List<double> li;
List_test_iterator.cpp: List<double>::Iterator it = li.begin();
List_test_iterator.cpp: List<double>::Iterator it2 = li.begin();
List_test_iterator.cpp: List<double> li;
List_test_iterator.cpp: List<double>::Iterator it = li.begin();
List_test_iterator.cpp: List<double>::Iterator it2 = li.begin();
List_test_iterator.cpp: List<double> li;
List_test_iterator.cpp: List<double>::Iterator it = li.begin();
View ripgrep on GitHub
pushd, popd
pushd
and popd
are shell builtins that see quite a lot of use in scripting, but seem rare outside that context.
popd
can be very useful in combination with z
, as an easy way to undo the last jump and reset the directory stack.
➜ Downloads z files
➜ Files popd
~/Downloads ~/Files/eecs280/project4 ~/Files/website ~/Files/website/src ~/Files/website/src/components ~/Files/gdb_printers/libstdcxx/v6 ~/Files/gdb_printers/libstdcxx ~/Files/gdb_printers ~ ~/Files/DebuggerSearch/resources ~/Files/website/content ~/Files/website/content/blog ~/Files/website/content/blog/unix_shell_commands
➜ Downloads
mdfind (MacOS)
mdfind
is a way to access spotlight from the command line in MacOS.
This is different from locate
, which works by keeping a database of handles on the system.
Spotlight actively indexes everything; even a newly-generated file will be found.
➜ Downloads wget http://code.jquery.com/jquery-3.4.1.min.js
--2021-08-25 21:12:02-- http://code.jquery.com/jquery-3.4.1.min.js
Resolving code.jquery.com (code.jquery.com)... 2001:4de0:ac18::1:a:2b, 2001:4de0:ac18::1:a:3a, 2001:4de0:ac18::1:a:1a, ...
Connecting to code.jquery.com (code.jquery.com)|2001:4de0:ac18::1:a:2b|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 30638 (30K) [application/javascript]
Saving to: ‘jquery-3.4.1.min.js.1’
2021-08-25 21:12:02 (1.15 MB/s) - ‘jquery-3.4.1.min.js.1’ saved [88145]
➜ Downloads mdfind jquery-3.4.1.min.js | head -1
/Users/brycesmith/Downloads/jquery-3.4.1.min.js
See my post on this tool.
zsh-autosuggestions
Maybe not a CLI app per se, zsh-autosuggestions
does exactly what it sounds like; provides completions for zsh
.
For example:
zsh-autocomplete
often successfully completes my commands, but I find it more useful for inspiration encountering novel tasks.
Available on github.
Closing
Composability is an important aspect of Unix workflow.
When working in environments you have full control over, I find the tools mentioned in this post very useful.
Even when working via ssh
, many of these tools are flat shell scripts; they can run without special permissions.