×
< BLOG
Hardware & Software

Aliases in Linux

March 10, 2016

Guest Author

Photo Credit: alias via txmx 2 cc

This article elucidates the alias command, its purpose, and how to create permanent alias changes by editing bash startup scripts. These topics are important to grasp for the CompTIA Linux+ exam.

What are Aliases in Linux?

Alias commands in Linux enables you to create simple new commands or abbreviations for an existing individual command or groups of commands. Aliases provide a way to customize the shell. Other customization options entail editing environment variables.

To create an alias, follow this example:

alias alias_name=’command(s)’

Delete Aliases

Remove an alias by using the unalias command with the specific alias name. Follow this syntax:

unalias alias

List Current Aliases

To see a list of current aliases on your system or within the shell, enter the alias command with no arguments. Use the alias command with the alias name to see its definition.

Reasons for Using Alias Commands

Reduce Typing and Create Shortened Versions of Multiple Commands

Aliases enable you to add groups of commands (executing consecutively) into a one word or character command. If you prefer to reduce typing to an absolute minimum, then you can even create aliases defined by a single character. For example, the alias “c” simplifies the clear command.

alias c=’clear’

Also, for the sake of time, grouping together multiple commands increases efficiency for tasks requiring the execution of consecutive program actions.

Use Preferred Command Options for Command Default

Redefine the default functions of commands. This shortens the typing effort on the user’s behalf.

For example, you may prefer to employ the ls -alF option often by default. Rather than repeatedly typing and remembering these options, create an ls alias for the option. Setting the alias would appear like this:

alias ls=’ls -alF’

Correct Common Typos and Misspellings

This reason for using an alias alleviates the concerns of the haphazard typist who commonly mistypes or slightly misspells command names.

Set Uniform Command Names Across Different Linux Distributions

Aliases settle discrepanies of command variations across Linux distributions for groups of users within a common environment. In Linux the major distributions of Red Hat, Debian, CentOS, and additional distros each contain similar commands, but have small variations.

When you create aliases in the bash shell, the alias remains nonpersistent unless you initiate the change in the bash startup scripts and configuration files.

How to Make Aliases Persistent by Editing the Bash Startup Scripts

You can make the aliases persistent (permanent) by adding them to one of these bash login configuration files:

  • ~/.bash_login
  • ~/.profile
  • ~/.bash_profile 

If more than one of these files exist, the system reads the first listed file and ignores the rest. Also, you can add aliases by editing the ~/.bashrc configuration file.

Edit the global bash configuration files to set aliases for all users. The files are one of these:

  • /etc/profile
  • /etc/profile.d
  • /etc/bashrc
  • /etc/bash.bashrc

Are Alias Commands Worth the Effort?

The process for learning the command-line entails practicing commands. Employing aliases, even though not used often, provides another opportunity for increasing command-line proficiency.

Although you may not initially find this command useful, try to contrive reasons to use it for overall system administration practice. Savvy sysadmins discover ways to increase efficiency. Aliases provide a means to enhance efficiency.

This article is one of several exploring commands and topics covered by the CompTIA Linux+ exam

subscribe by email

Stay Ahead

Phoenix TS needs the contact information you provide to us to contact you about our products and services. You may unsubscribe from these communications at anytime. For information on how to unsubscribe, as well as our privacy practices and commitment to protecting your privacy, check out our Privacy Policy.