Unix: Aliases for Frequently Used Commands in bash/sh

Practice



So, you're a Unix administrator. And you often work at the command line, carrying out various tasks.

However, quite often you find yourself needing to type the same sequence of commands and parameters over and over again during your work. For example, you run "ps -ax", or "ls -lh" day after day. Or even longer commands.

So let's create simple letter aliases for them - that is, replacements.

For example, instead of "ls -lh" we want to type just "lh" - yes, easily, nothing impossible about it!


Go to your home directory and open for editing the file ".profile" for FreeBSD or Debian/ubuntu, or ".bash_profile" for CentOS/RedHat (it's hidden). Add the lines you need to the file, following the example below:

...
alias lh="ls -lh"
alias px="ps -ax"

Here, as is obvious - what comes before the equals sign is the alias that you'll be able to type. And after the equals sign comes the actual command, which can be much more complex than the ones shown in the example (want to rebuild the kernel with a single command "doit"? just kidding)

This technique works on Linux Debian (and ubuntu), Linux CentOS (and RedHat), and FreeBSD.

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "LINUX operating system"

Terms: LINUX operating system