Linux command: alias

Quick startaliasCommand, used to create a shortcut to another command

In general, always run the program with a set of options you like to use.

For example, takelscommand. By default, it only prints very little information:

currently using-alOption, it will print out more useful content, including file modification date, size, owner and permissions, and also list hidden files (files beginning with ".".:

You can create a new command, for example I like to call itll, This is an aliasls -al.

You can do this in the following ways:

alias ll='ls -al'

Once you’re done, you can callllJust like a regular UNIX command:

Call nowaliasThe list without any options will list the defined aliases:

The alias will work until the terminal session is closed.

To make it permanent, you need to add it to the shell configuration, which may be~/.bashrcor~/.profileor~/.bash_profileIf you use the Bash shell, it depends on the use case.

If the command contains variables, be careful to use quotation marks: use double quotation marks to parse the variable when it is defined, and use single quotation marks to parse it when it is called. Those two are different:

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

\$PWD is the current folder where the shell program is located. If you navigate to the new folder now,lscurrentList the files in the new folder,lsthisThe files in the folder you were in when you defined the alias will still be listed.

ThisaliasThis command can be used in Linux, macOS, WSL and wherever you have a UNIX environment

Download mine for freeLinux Command Manual


More cli tutorials: