An alias allows us to come up with our own name for a command or group of commands. This is especially useful for long convoluted commands that we might like to use regularly or if we’d just prefer to use our own syntax. We can use the alias command at the command line if we want to use an alias for our current session, but it will disappear once we log out. We can use the alias command like the following example.

alias whateverwewant="command | command | command"

or

alias copy="cp"

To make an alias permanent, we have to add it to a user’s .bashrc file located in their home directory, for example /home/user/.bashrc. We can add it basically anywhere in there, but there should be an existing section for aliases so it would be best practice to put them all in one place. The following command is a good example of something we would not want to have to type out more than once. It will give us a recursive hierarchical view of all files and directories starting from the current directory.

alias showall="ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'"

Any changes you make to .bashrc will be made on that user’s next login. In the event that a command needs sudo privileges, the alias envoking that command will not work unless it is in the root user’s .bashrc file located in /root/.bashrc.

About Canadian Web Hosting

Since 1998, Canadian Web Hosting has been providing on-demand hosting solutions that include Shared HostingVirtual Private Servers (VPS), Cloud HostingDedicated Servers, and Infrastructure as a Service (IaaS) for Canadian companies of all sizes. Canadian Web Hosting is SSAE 16 Type II SOC 2 certified, ensuring that their processes and business practices are thoroughly audited against industry standards. Canadian Web Hosting guarantees a 100% network uptime, and a total money-back guarantee that backs everything they do. Customers can get help by calling 1-888-821-7888 to get 24/7 support. For more information, visit them at www.canadianwebhosting.com, or get the latest news by following them on Twitter at @cawebhosting.