AI Workshop: learn to build apps with AI →
Advanced Commands: alias - Create Shortcuts

Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.


It’s common to always run a program with a set of options you like using.

For example, take the ls command. By default it prints very little information:

while using the -al option it will print something more useful, including the file modification date, the size, the owner, and the permissions, also listing hidden files (files starting with a .):

You can create a new command, for example I like to call it ll, that is an alias to ls -al.

You do it in this way:

alias ll='ls -al'

Once you do, you can call ll just as if it were a regular UNIX command:

Now calling alias without any option will list the aliases defined:

The alias will work until the terminal session is closed.

To make it permanent, you need to add it to the shell configuration, which could be ~/.bashrc or ~/.profile or ~/.bash_profile if you use the Bash shell, depending on the use case.

Be careful with quotes if you have variables in the command: with double quotes the variable is resolved when the alias is defined; with single quotes it’s resolved when the alias is run. Those 2 are different:

alias lsthis="ls $PWD"
alias lscurrent='ls $PWD'

$PWD refers to the current directory the shell is in. If you now navigate away to a new folder, lscurrent lists the files in the new folder, lsthis still lists the files in the folder you were when you defined the alias.

The alias command works on Linux, macOS, WSL, and anywhere you have a UNIX environment

Lessons in this unit:

0: Introduction
1: su - Switch User
2: sudo - Superuser Do
3: passwd - Change Password
4: ping - Test Network
5: traceroute - Trace Network Path
6: history - Command History
7: export - Set Environment Variables
8: crontab - Schedule Tasks
9: ▶︎ alias - Create Shortcuts
10: man - Manual Pages
11: tar - Archive Files
12: gzip - Compress Files
13: gunzip - Decompress Files
14: basename - Strip Directory
15: dirname - Extract Directory
16: nano - Text Editor
17: vim - Vi Improved Editor
18: emacs - Text Editor
19: ed - Line Editor
20: How to use Netcat
21: How to download a file from a server using the terminal