Alias - a command that saves you time
Alias
You may be using aliases without knowing it if you use Linux, since a command as common as ll
is an alias that already comes by default in distributions like Ubuntu.
alias ll='ls -alF'
Alias is an old cross-platform command that in our beloved Unix has inherited it with zsh and bash.
Alias is by definition a command for command line interpreters (shells), where a word or string is replaced by another string.
Alias is used to abbreviate or add default arguments to a commonly used command.
Alias Syntax
To display the system aliases in Debian distributions, a alias
is sufficient for all other unix distributions alias -p
.
alias [-p] [name[=value] ... ]
Use of aliases
alias name="value"
delete an alias
unalias name="value"
Permanent alias
The use of aliases depends precisely on the use that we give him at session level, when you create an alias with the previous syntax, it is created for the active session, but if we close session or we restart the pc, these aliases will be erased.
If we want the aliases to be saved we will have to introduce them in the hidden file ~/.bashrc.
With our favorite editor we will do a sudo nano ~/.bashrc
to edit it and add our aliases. In any part of the document with this syntax alias name='value'
.
Examples
With a simple r and enter I am root
alias r='sudo -i'
If we want to generate a strong password under console I have programmed xxx and I get the password
alias xxx='openssl rand -base64 20'
To clear the cache memory in our Debian based distributions.
alias mem='sudo -i && sync && echo 3 > /proc/sys/vm/drop_caches'
So common in our systems
alias update='sudo apt update && sudo apt upgrade'
To know our public ip
alias ip='curl ipinfo.io/ip'
To view our open ports
alias p='netstat -tulanp'
The use of aliases is limited only by our imagination or needs, it is a very useful command for those who live in bash.
Posted with STEMGeeks
https://twitter.com/t_r0str0/status/1374578297632391169
Congratulations @r0str0! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :
Your next target is to reach 600 upvotes.
You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
Check out the last post from @hivebuzz:
Minor note, but the
unalias
command (at least in Bash) just needs the alias you want to remove and not what it's aliased too. So for instanceunalias ls
would work whereas this is what happens if you try to add the ="value" partIf you want to be really fancy you can just remove all aliases with
unalias -a
.There's definitely a lot of neat features in all the shells out there, so it's great to see some posts like this talking about some of them
To me what I find charming is that someone replicates this type of publications, thank you very much, you are absolutely right, the reason for my imprecision is that I usually remove few aliases, but I should have told it in a more complete way. Noted.
Alias is an infinite command, which I appreciate very much as it saves you a lot of time, and creates good times, who has not laughed with a friend who tells you; I am unlearning linux thanks to alias.
This blog goes in the direction of Debian and derivative users, but I wanted to remember also thanks to you, how to make our permanent aliases for shells other than bash with our favorite editor.
ZSH - ~/.zshrc
Fish - ~/.config/fish/config.fish