Find out if shell command is aliased or not

h‮:sptt‬//www.lautturi.com
Find out if shell command is aliased or not

To find out if a particular shell command is aliased on a Linux or Unix system, you can use the alias command without any arguments. This command will display a list of all the currently defined aliases on the system, along with their definitions.

For example:

$ alias
alias ls='ls --color=auto'
alias ll='ls -l'
alias la='ls -la'

In this example, the alias command shows that the ls, ll, and la commands are aliased to the ls --color=auto, ls -l, and ls -la commands, respectively.

To check if a specific command is aliased, you can use the grep command to search the output of the alias command for the name of the command.

For example:

$ alias | grep ls
alias ls='ls --color=auto'

This will display the alias definition for the ls command, if it is defined. If the command is not aliased, the grep command will not produce any output.

Alternatively, you can use the type command to check if a specific command is an alias. The type command will display the type of a command, which can be either an alias, a shell function, a built-in command, or a regular executable file.

For example:

$ type ls
ls is aliased to `ls --color=auto'

This will display the type of the ls command, along with its definition if it is an alias. If the command is not an alias, the type command will display its type and the path to the executable file.

Note that the alias and type commands only work for the current shell session, and they will not show any aliases that are defined in the system-wide configuration files (such as /etc/bash.bashrc or /etc/bash.bash_aliases). To find out if a command is aliased in the system-wide configuration, you will need to check the contents of these configuration files.

Created Time:2017-10-28 20:40:30  Author:lautturi