Linux Shell Productivity: Aliases & Navigation Shortcuts¶
DevOps engineers often work with long, complex commands. Learning how to create shortcuts and navigate the shell efficiently can save hours of time every week.
โก Alias Command¶
An alias is a custom shortcut for a long command. It allows you to replace a complex string with a single word.
1. Creating a Temporary Alias¶
You can create an alias by using the alias command. However, manual aliases are not passed to child processes.
[opc@new-k8s ~]$ alias c="clear"
[opc@new-k8s ~]$ c
# (Terminal screen clears)
[opc@new-k8s ~]$ bash # Enter a new child shell
[opc@new-k8s ~]$ c
bash: c: command not found # Alias is missing in child shell
[opc@new-k8s ~]$ exit # Return to original shell
2. Listing and Removing Aliases¶
To see all active aliases, run alias without arguments. To remove an alias, use unalias.
[opc@new-k8s ~]$ unalias c
[opc@new-k8s ~]$ c
bash: c: command not found
๐พ Persisting Aliases (.bashrc)¶
Manual aliases are lost when you close your terminal. To make them permanent, add them to your ~/.bashrc file and reload the configuration using the source command.
[opc@new-k8s ~]$ echo 'alias c="clear"' >> ~/.bashrc
[opc@new-k8s ~]$ source ~/.bashrc # Apply changes immediately
[opc@new-k8s ~]$ bash # Enter a new child shell
[opc@new-k8s ~]$ c # It works now!
[opc@new-k8s ~]$ exit
Now, c will work in every new terminal session.
๐ Command History¶
The shell keeps a record of every command you type. You can use this history to re-run commands without retyping them.
1. Viewing History¶
Run history to see a numbered list of your past commands.
[opc@new-k8s ~]$ date
[opc@new-k8s ~]$ whoami
[opc@new-k8s ~]$ ls
[opc@new-k8s ~]$ history | tail -n 5
501 date
502 whoami
503 ls
504 history
2. Using History Shortcuts¶
!!โ Run the last command again.!501โ Run command number 501 from your history.
๐งญ Fast Navigation Shortcuts¶
Moving between directories efficiently is key to shell productivity.
1. Switch to Previous Directory (cd -)¶
If you were just in /tmp and moved to your home directory, you can jump back instantly using -.
[opc@new-k8s ~]$ cd /tmp
[opc@new-k8s tmp]$ cd ~
[opc@new-k8s ~]$ cd -
/tmp
[opc@new-k8s tmp]$ cd -
/home/opc
2. Return Home (cd ~ or cd)¶
Typing cd without any arguments or cd ~ always returns you to your home directory.
๐ Reverse Search (Ctrl + R)¶
Instead of scrolling through history with arrow keys, you can search for a previous command by typing part of it.
- Press
Ctrl + R. - Start typing the command (e.g.,
alias). - The shell will find the most recent matching command (like
alias c="clear"). - Press
Enterto run it or use arrow keys to edit it.
๐ง Productivity Quiz¶
Which command allows you to return to the directory you were in immediately before the current one?
๐ Want More Practice?¶
Check out our other shell guides: ๐ Linux Shell Basics: Variables & PATH
๐ฌ DevopsPilot Weekly โ Learn DevOps, Cloud & Gen AI the simple way.
๐ Subscribe here