Use the CLI Like a Sysadmin

As a former infosec student, SRE, and now Sysadmin, I have been using the command line for a few years now. I get a little irked when I see command line tip articles that are written on zsh, and prompt customization, etc.
This doesn’t help you get your work done on a cluster or in the cloud. In my opinion it’s just another way to shoot oneself in the foot. It takes away the agnostic nature of Bash and it substitutes it with something you’ve grown dependent on. Do you REALLY need to see the exact NodeJS version in your PS1 when you cd into the directory?
As Sysadmins, we witness plenty of interesting behaviors on the nodes we manage, and we can’t help but ask, “how come computing specialists are not comfortable on the command line?”
One of our favorites is without a doubt: sudo whoami
. It’s since become a meme at the office and we had a professional calligrapher write it for us.

The point I’m trying to make is that anyone who calls themselves a ‘Technology Professional’ shouldn’t be limited to a graphical interface in order to accomplish their tasks.
Here are some tips to make that easier.
The BASHRC
There’s no point in over-complicating your .bashrc. I’ll see users doing all sorts of things in there and shortly after contact us for help because things will break.
Simplicity is your best friend. Use the .bashrc for some aliases and a few exports (ex. export EDITOR=vim). There’s no need to index every single executable file on the system EVERY TIME you open a new terminal (People have done this). You slow yourself down, slow others down, and no one is happy about it.
A good rule of thumb is that your .bashrc should not take up more than one screen. If you need to pipe it into less, you’ve already over-done it.
Navigation
One of the reasons I (and others) prefer a terminal over using a GUI is the raw speed of moving to and from directories.
Let’s pretend you need to move into /etc/systemd/system/
from your project directory in /root/projects/units/
.
You know you will need to jump back into your projects directory.
There are two options:
cd
into/etc/systemd/system
then typecd -
- instead of
cd
you usepushd
to enter/etc/systemd/system
and thenpopd
to jump back into your previous directory.
When using ‘-’ as your argument for the cd
command, you’re using the shorthand for the $OLDPWD
environment variable that is reset every time you change a directory. If you need to move around a bit without wanting to keep track of your $OLDPWD
, pushd
is there to save you.
Using pushd
will save the current directory before you move, this allows you to jump back to it at any point in time by typing popd.
Even if you move around the filesystem.
Example:
- I’m currently in
/root/projects/units/
- I write
pushd /etc/systemd/system/
- I
cd
into/etc/ssh/
- I write
popd
and I’m back in/root/projects/units/
Makes life easy without having to install anything :)
Using Bang
How many times have you forgotten to write sudo before a long command? Don’t tell me, I know.
I’ll see someone hitting their arrow key and then proceed to move their cursor to the beginning of their command. Just writing that hurts.
sudo !!
This takes your previous command and allows you to prepend it with sudo
. Learning to do this has collectively saved me hours of cursor movement over the years.
You can also append items to the previous command without having to rewrite the command, among other things.
What if you want to reuse the last argument in a command?
This is useful if you’re working with long paths, rather than writing them out (or relying on tab completion), you can simply use:
!$
!$
expands to the last argument of the previous command.
Here’s an example:
Sometimes I’ll write a script
vim /usr/local/bin/script.sh
I need to chmod it in order for it to be executable, so instead of tab completing or writing it out I can simply:
chmod 755 !$
Further delaying carpal tunnel syndrome.
Since we’re on the topic of using bang (!), you can rerun the most recent command with !<command> instead of spamming the arrow key to find where you left off.
If I’m editing a config file inside of some arbitrary directory and I need to edit the file again. All I have to type is !vim
and it will take me right back to editing without having to think about it.
Closing
These tips should improve your productivity significantly. You don’t need zsh or external tools to be fast. Focusing on the fundamentals may seem boring. Boring can be useful, Boring is consistent, and consistency is exciting.
xo