Linux commands: alias
A quick guide to the `alias` command, used to create a shortcut to another command
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 like it was 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: using double quotes the variable is resolved at definition time, using single quotes it’s resolved at invocation time. Those 2 are different:
alias lsthis="ls $PWD"
alias lscurrent='ls $PWD'
$PWD refers to the current folder the shell is into. 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
aliascommand works on Linux, macOS, WSL, and anywhere you have a UNIX environment
download all my books for free
- javascript handbook
- typescript handbook
- css handbook
- node.js handbook
- astro handbook
- html handbook
- next.js pages router handbook
- alpine.js handbook
- htmx handbook
- react handbook
- sql handbook
- git cheat sheet
- laravel handbook
- express handbook
- swift handbook
- go handbook
- php handbook
- python handbook
- cli handbook
- c handbook
subscribe to my newsletter to get them
Terms: by subscribing to the newsletter you agree the following terms and conditions and privacy policy. The aim of the newsletter is to keep you up to date about new tutorials, new book releases or courses organized by Flavio. If you wish to unsubscribe from the newsletter, you can click the unsubscribe link that's present at the bottom of each email, anytime. I will not communicate/spread/publish or otherwise give away your address. Your email address is the only personal information collected, and it's only collected for the primary purpose of keeping you informed through the newsletter. It's stored in a secure server based in the EU. You can contact Flavio by emailing flavio@flaviocopes.com. These terms and conditions are governed by the laws in force in Italy and you unconditionally submit to the jurisdiction of the courts of Italy.