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 dir='ls -l'
alias ls='ls --color'
alias mv='mv -i'
alias rm='rm -i'

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 the shell will prompt for confirmation before deleting files. This helps avoid accidental deletion of files, which can be particularly hazardous ...

Get Learning Red Hat Linux, Third 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.