First of all, for those that don’t know what an alias is, alias is a way to pair a command with a name of your choice. For example I use all the time the command ls passing arguments -lah. So I made an alias for this command with the name ll. From now on whenever use the ll command the shell knows to execute the ls -lah.
An alias lasts for a session. When the session ends the alias exprires.
So before telling you how to set alias and view aliases of the system, you must know how long an alias should exist.
If you want to get all the alias for the session you are just type
If you want to set an alias for the current session just type
$alias ll='ls -lah'
If you want to remove an alias for the current session just type
If you want to add an alias permanently, you have to edit your bash file.
For linux mint this files is name bash.bashrc and is located under /etc directory.
The filename and directory varies on each linux distribution.
Aliases in Centos
You can add a permament alias in centos using the following simple steps:
1st step Create a file in /etc/profile.d/ directory
create a file with filename relative to the command you want to make an alias (this is just a mnemonic hint) inside the directory: /etc/profile.d/ as is shown in the following example:
In this example I need to create an alias for ldapsearch, so I name my file ldapsearch.sh
2nd step Define the alias in the file
Insert in the alias’s definition file something like the following:
# Initialization script for bash and sh
# export AFS, if you are in AFS environment
alias ldapsearch='/usr/bin/ldapsearch -h ds.example.com -D uid=searchuser,dc=example,dc=com -w searchpass -x -b dc=example,dc=com -s sub -LLL'
3rd step Give the right permissions to the file
You have to run the following command, where ldapsearch.sh is an example
chmod 755 /etc/profile.d/ldapseach.sh
4th step Restart your session Or Source the file you created
Now you have to either restart your session, by exiting the terminal, and open a new one, or use the following command:
Now you are ready to create your own aliases, to make your terminal experience even better!