Little Girl's Mostly Linux Blog

Alias

Alias

This page was last updated on October 10, 2013.

Create a temporary alias

You can create a temporary alias that is valid only for the current session and will be forgotten by the system when you close the terminal window. To do this:

  1. Open a terminal window.
  2. Check if the name you’d like to give your alias is already being used by the system by typing this command, replacing name with the name you’d like to give the alias:
    which name

    Press the Enter key. If the name is already being used, repeat this step with another name as many times as needed to find one that isn’t being used.

  3. Type this command, replacing name with the name you chose and replacing command with the command you’d like the alias to perform:
    alias name='command'

    Press the Enter key.

    • For example:
      alias details='ls -l'

      Now I can type details instead of ls -l to see a detailed listing of files in a directory.

Create a personal alias list (method 1)

To create your own alias list:

  1. Open a text editor and type the command for each alias on a separate line.
    • Example:
    • alias1='command1'
      alias2='command2'
      alias3='command3'
      alias4='command4'
      
  2. Save the file as .bash_aliases in your home directory (for example, /home/steve/.bash_aliases). Note that hidden files must be turned on in your file manager for this file to be visible.
  3. Close the text editor.

Now any time you open a terminal window, the aliases you have defined will be available for you to use.

Create a personal alias list (method 2)

To create your own alias list:

  1. Open a text editor and type the command for each alias on a separate line.
    • Example:
    • alias1='command1'
      alias2='command2'
      alias3='command3'
      alias4='command4'
      
  2. Save the file as myaliaslist wherever you’d like to keep it. For the sake of this example, let’s say you saved it to the /home/username/ directory.
  3. Open the .bashrc file in your /home/username/ directory with a text editor. Note that hidden files must be turned on in your file manager for this file to be visible.
  4. Type this line at the bottom of the file to get Bash to use your alias list:
    source /home/username/myaliaslist
  5. Save the file.
  6. Close the text editor.

Now any time you open a terminal window, the aliases you have defined will be available for you to use.

Check which aliases you have defined

Type this command in a terminal window to check if you have any aliases defined in your .bashrc file:

alias

Obligatory Happy Ending

And they all lived happily ever after. The end.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Comment:

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: