1. Home
  2. Training Library
  3. Linux Administration Bootcamp Introduction | CSL4 V2 A3.1 |

Shell Aliases

Contents

keyboard_tab
Linux Administration Bootcamp
Installing and Connecting to a Linux System
2
Linux Boot Process and System Logging
33
Disk Management in Linux
36
Partitions
PREVIEW6m 50s
38
User Management in Linux
Shell Scripting with Linux
54
55
Start course
Overview
Difficulty
Beginner
Duration
7h 28m
Students
2
Description

In this course, you will learn how to install a Linux system and connect to it, whether that be on Mac or Windows.

Transcript

This lesson covers creating, deleting and persisting aliases. If you find yourself typing the same command over and over again, you can create a shortcut for it called an alias. An alias can be thought of as a text expander, creating aliases for commands that are really long, or that you use often is a common practice. For example, if you type ls-l frequently, you may want to abbreviate it to ll. As a matter of fact, this alias often comes predefined on many Linux distributions.

The alias command can list or create aliases. If you run alias without any additional information on the command line, it displays the list of current aliases that are set. If you wanna create an alias, use alias space the alias name = and the value for that alias. Aliases don't have to be used for just shortcuts, they can be used to fix common typing errors. For example, if you end up typing grpe, and you mean to type grep, you can create an alias. And whenever you accidentally type grpe, alias will fix that for you, and spell it grep. You can also use aliases to make your work environment similar to that of another platform.

For instance, in Windows, cls clears the screen, but in Linux, the equivalent command is clear. You can create these shortcuts to make you feel more at home. To remove an alias, type unalias and the name of the alias. Or, to remove all aliases, use unalias -a. If you were to create some aliases and logout and back in, your aliases would be lost.

To make them persist between sessions, add them to your dot files, such as .bash_profile. The downside to creating several aliases is that when you're on a system that does not have your aliases, you might feel lost. If you wanna be able to work effectively on any Linux system that you have access to, keep your alias usage to a minimum.

Another way to handle this situation is to simply copy your configuration files to each Linux system that you're going to work on. Let's say you run ls -l a lot, let's make this an alias, make it shorter. Let's alias ll to be ls -l. So now when you type ll, you'll get the same result as ls -l.

Let's say you like to type cls because you come from a Windows background. Cls is not available on Linux, the equivalent command is clear. You could create an alias for cls that equals clear. So now when you type cls it will clear the screen. To list aliases just use the alias command. To make them persist, you can add it to your bash_profile file. Let's do this, let's add mycls.

You can see that that's not set. Let's logout and log back in. And you can see that mycls is set. The alias command lists and creates aliases, while the unalias command deletes aliases. To persist your aliases between logins, add them to your dot files.

About the Author