The Alias command in GNU/Linux and helpful tips with it
There is a terminal command called alias, that many users may not know exists, but likely will be very happy to find out about it.
The alias command, allows you to redefine what you type, to make things happen. It gives you the option to map large commands to an alias that you may run then instead of the large command to execute it.
A very straightforward (although risky) example of this would be:
alias dla="rm -rf *"
The reason this is both handy, but risky, is now if I enter any directory and simply type dla, I will delete everything in that directory. I did not add sudo to this, purposely, so at least system files canâ€™t be deleted through this method, but caution must still be used. However, once accustomed to it, this alias combined with others like it, can speed up workflow exponentially.
Tip: Type alias to display the list of aliases set on the Linux machine.
Another that I use frequently, since I use nginx as my webserver of choice on all my remote servers, and I have to restart or reload nginx often when mucking around with configurations, so I use the alias:
alias n="sudo service nginx restart"
Now, I simply need to type the letter n, and the command will be executed, saving me insane amounts of time and keystrokes.
Here are some other aliases that you might find useful!
- alias l="ls -al" -- now, simply type a lowercase L, and receive a more detailed list of files/folders in the current directory
- alias dla="rm -ri *"-- a much safer but more annoying shortcut. This command will delete everything (files and folders) in a directory, but will confirm each and every deletion one by one as it happens. While tedious, this can save you huge headaches from accidentally deleting a key file.
- alias update="sudo apt update && sudo apt upgrade"-- one word will start the upgrade process, if need be, when using Debian based systems.
- alias psmem="ps auxf | sort -nr -k 4"-- This will show you your processes, ordered by highest RAM usage.
- alias pscpu="ps auxf | sort -nr -k 3"-- This will show you your processes ordered by highest CPU usage.
- alias home='cd /home/martin/' -- Switch to the /home/martin/ directory when you type the alias.
Aliases can make things so much faster when working with the command line, but always be careful not to set aliases up that could destroy your system with a simple keystroke, like a="sudo rm -rf *"as this runs far too many risks.
Now you: Do you use any aliases? What? Show us in the comments!Advertisement