Over the course of my years as a SysAdmin I’ve come across useful tips/tricks that have helped me navigate the terminal more efficiently and made my job much easier. So I thought why not share them here as well, some of them you may know and some you may be hearing about for the first time
Tip 1: Using !! to redo previous command
I can’t count how many times I’ve had to redo a command and coming across this has helped me save plenty of time.
How this works is !! calls the last command you ran. Now for example some useful use cases are: rerunning the last command but with sudo. sudo !! solves that for you without you having to retype the full command with sudo before hand. I know plenty of Admins can understand the frustration of forgetting to type in sudo before running a command.
Tip 2: CTRL + R
Working on the terminal and typing commands constantly you can sometimes forget a command and the full syntax that you may have run in the past or just recently. CTRL + R has been great in finding a command that I may have run before. Especially for longer syntax commands, it’s a bit tricky to just retype the full command. CTRL +R allows you to search history by whatever bit you can remember. Let’s take an example:
Let’s say you recently ran an ansible-adhoc command:
ansible databases -b -m yum -a “name=mariadb-server state=latest”
and you wish to run another adhoc command and by using CTRL + R and by searching for “ansible” you can access the last ansible command you run and from there can rewrite command as you wish. Time efficient if you ask me
Tip 3: Aliases for Frequent Commands
If you are consistently writing certain commands with certain flags and arguments, long or short. You can always create a shortcut by creating an alias for it within your ~/.bashrc or ~/.bash_aliases file
alias ll=’ls -alF’
alias up=’sudo apt update && sudo apt upgrade -y’
these are just some examples, you can imagine how much easier this makes things for a SysAdmin. Feel free to get crazy and experiment with what works for you.
Remember, you will need to run source ~/.bashrc or restart your terminal for new aliases to take effect
These are only just some tips that you may or may not find useful but as you’ll see, with more time spent on the CLI you’ll come across more tricks like these making your life as an Admin much easier. Hope I was able to help and hope these tricks were useful. I’ll see you next week with a new post.
Hasnain
Linux Systems Administrator | Aspiring Devops Engineer
Leave a comment