Thursday 23 April 2020

Unix/Linux ‘alias’ command examples

Linux Study Materials, Linux Certification, Linux Guides, Linux Exam Prep

Unix and Linux aliases are a really nice way of customizing the command line to work the way you want it to work. With alias commands, you’re essentially doing a little programming, and creating new Unix and Linux commands custom-tailored to the way you work. You can create aliases to use instead of existing commands, and you can also create aliases as Linux command pipelines.

I’m not going to describe my Linux aliases too much, but mostly just put them out here so you can see how they work. One thing I should note is that this syntax assumes you’re using the Bash or Korn shells. The syntax is a little different with other shells, like csh, but I don’t remember the syntax differences, so I’m just going with the Bash alias syntax.

Sample Linux aliases


Here’s a list of sample aliases I currently use (or have used in the past):

alias cd..="cd .."
alias cd...="cd ../.."
alias cd...="cd ../.."
alias gi="grep -i"
alias l="ls -al"
alias lm="ls -al | more"
alias lf="ls -FG"
alias h=history
alias hm="history | more"

# places
alias bin="cd /Users/al/tomcat/bin"
alias html="cd /home/apache/html"

# file finding
alias ff="find . -type f -name "

# "que pasa" (an old friend said this a lot)
alias qp="ps auxwww | more"

# ssh: i modified this one for public consumption
alias fb="ssh al@foo.bar.com"

# for dos users
alias dir="ls -al"
alias md=mkdir
alias ren=mv
alias type=cat
alias search=grep

Hopefully most of those aliases are very straightforward. Note that any time you have spaces in your commands (to the right of the equal sign) you'll need to put quotes around your commands.

Using Linux aliases


Once you've configured your aliases you can use them just like a normal Linux command, like this:

cd...

The system responds by replacing your alias with the actual command(s) the alias represents:

cd ../..

The weirdest alias I've shown may be ff, which I use like this:

ff some_file

which expands to this:

find . -type f -name some_file

Related Posts

0 comments:

Post a Comment