Get the highlights in your inbox every week.
15 command-line aliases to save you time
15 command-line aliases to save you time
Some aliases are included by default in your installed Linux distro.

opensource.com
Linux command-line aliases are great for helping you work more efficiently. Better still, some are included by default in your installed Linux distro.
This is an example of a command-line alias in Fedora 27:
The commandalias
shows the list of existing aliases. Setting an alias is as simple as typing:
alias new_name="command"
Here are 15 command-line aliases that will save you time:
-
To install any utility/application:
alias install="sudo yum install -y"
Here,
sudo
and-y
are optional as per user’s preferences: -
To update the system:
alias update="sudo yum update -y"
-
To upgrade the system:
alias upgrade="sudo yum upgrade -y"
-
To change to the root user:
alias root="sudo su -"
-
To change to "user," where "user" is set as your username:
alias user="su user"
-
To display the list of all available ports, their status, and IP:
alias myip="ip -br -c a"
-
To
ssh
to the servermyserver
:alias myserver="ssh user@my_server_ip”
-
To list all processes in the system:
alias process="ps -aux"
-
To check the status of any system service:
alias sstatus="sudo systemctl status"
-
To restart any system service:
alias srestart="sudo systemctl restart"
-
To kill any process by its name:
alias kill="sudo pkill"
-
To display the total used and free memory of the system:
alias mem="free -h"
-
To display the CPU architecture, number of CPUs, threads, etc. of the system:
alias cpu="lscpu"
-
To display the total disk size of the system:
alias disk="df -h"
-
To display the current system Linux distro (for CentOS, Fedora, and Red Hat):
alias os="cat /etc/redhat-release"
29 Comments, Register or Log in to post a comment.
One thing alias is very picky about is that you cannot have any spaces between the alias name and the equals sign, or between the equals sign and the quotes at the beginning of the command.
Absolutely true! :)
That's bash, not alias itself. Aliases are just a special kind of bash variables, and you gotta be careful with spaces whenever writing scripts with vars also.
For number 7, I found a much more helpful way to do that was to add shortnames to your ~/.ssh/config file. That way, the shortnames work with all ssh related tools like scp, rsync, etc. You can also add default user swaps on a personal shortened host basis, too.
Yes i too have my server aliases/shortnames stored in ssh config file
I believe install is already a posix command.
As is 'kill'.
Yep, and so is kill, so I wouldn't promote those aliases.
Also, IMHO, aliases should be short: what's more efficient, typing 'process' or 'ps -aux'?
Both are 7 characters long, tab-completion notwithstanding :)
I agree about kill and install which can be a bit problematic and regarding short aliases, i wanted to go with the ones which can be easily used by a beginner and remembered, learning different commands might be a challenge to a new linux user
Or
alias updg="for ops in update upgrade; do sudo apt $ops -y; done;
Nice!! Thanks for sharing :)
Very Helpful...
Bash functions are much more flexible than aliases. In particular, aliases can't take arguments.
Some specific quibbles:
alias root="sudo su -"
I'd use "sudo -i".
alias myserver="ssh user@my_server_ip”
The "_ip" suffix seems to imply using an IP address rather than a DNS name. There's rarely a good reason to do that.
alias kill="sudo pkill"
"kill" is already a built-in shell command. Aliasing it to something that uses sudo is a recipe for disaster. If you want "sudo pkill", you should probably just type "sudo pkill".
Several of these aliases are for commands I'd rather just type directly. Of course this is going to vary for different people.
I also agree most of these seem both dangerous and overkill. Why would you ever alias something that uses sudo to not use sudo? Plus everyone should learn/know these commands if they are system administrators.
Don't mean to shut OP down, just my take.
> "kill" is already a built-in shell command. Aliasing it to something that uses sudo is a recipe for disaster. If you want "sudo pkill", you should probably just type "sudo pkill".
You couldn't be more right there - and for a beginner (i.e. someone who actually uses aliases because they're usually on the same host) this is going to be doubly confusing when a desperate `kill -9 $PID` does absolutely nothing...
Correct, i must say kill and install are a bit problematic aliases, so i would just change that to something else. Also, sudo is optional if an experienced user like me is aliasing sudo than i know the consequences and would use it accordingly
The last one should be /etc/os-release which works on any distribution.
Thanks, I didnt know about this!! :)
Maybe better (possibly not universal): lsb_release -a
Wouldn't this potentially clash when you have different package managers? ie. Using flatpak to install packages from flathub:
flatpak install flathub org.gnome.
Would become:
flatpak sudo yum install -y flathub org.gnome.
Right it would clash, so maybe i would change the install alias to something like sinstall (software install) or ainstall or anything else
I wouldn't recommend using aliases for existing functions like `kill` - this breaks expected functionality: `which kill` prints the path a user who has forgotten about the alias wants to call but it's not what's actually being called so, unless the user remembers to check `alias`, there's going to be some confusion when `kill -9 $PID` has no effect.
I agree, maybe i would change it to somthing else so that it doesnt clash with the existing built-in command
What is 'ip -br -c a' supposed to do?
I tried it but see:
'Option "-br" is unknown, try "ip -help".'
-br stands for brief
Below is the man page entry for "ip" command:
-br,-brief
Print only basic information in a tabular format for better
readability. This option is currently only supported by ip addr
show and ip link show commands.
when I run one alias in bash it is working fine. But when I enter all aliases in an executable file "#!/bin/bash" none of the aliases is created. Any hint?
when you run the script ex- "./alias.sh", it executes in a sub-shell, you need to run it with "source alias.sh" so that the changes made by script are applied to the current env
source alias.sh or . alias.sh (dot alias.sh)
Is there any casual distro where policykit isn't set to allow normal user to ``systemctl reboot''?