Shell Aliases

Shell aliases make it easier to use commands by letting you establish abbreviated command names and by letting you pre-specify common options and arguments for a command. To establish a command alias, issue a command of the form:

alias name='command'

where command specifies the command for which you want to create an alias and name specifies the name of the alias. For example, suppose you frequently type the MS-DOS command dir when you intend to type the Linux command ls -l. You can establish an alias for the ls -l command by issuing this command:

alias dir='ls -l'

Once the alias is established, if you mistakenly type dir, you’ll get the directory listing you wanted instead of the default output of the dir command, which resembles ls rather than ls -l. If you like, you can establish similar aliases for other commands.

Your default Linux configuration probably defines several aliases on your behalf. To see what they are, issue the command:

alias

If you’re logged in as root, you may see the following aliases:

alias cp='cp -i'
alias l.='ls -d .* --color=tty'
alias ll='ls -l --color=tty'
alias ls='ls -color=tty'
alias mv='mv -i'
alias rm='rm -i'
alias vi='vim'
alias which='alias | /usr/bin/which -tty-only -read-alias -show-dot -show-tilde'

Notice how several commands are self-aliased. For example, the command rm -i is aliased as rm. The effect is that the -i option appears whenever you issue the rm command, whether or not you type the option. The -i option specifies that ...

Get Learning Red Hat Enterprise Linux & Fedora, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.