alias - Unix, Linux Command


Advertisements


NAME

alias - Alias command allows you to make new shortcuts and synonyms for commonly used comands.

SYNOPSIS

alias [name=['command']]
or
alias New_shortcut='yourcommand -arguments'

DESCRIPTION

Aliases allows a user to create simple names or abbreviations (even consisting of just a single character) for commands regardless of how complex the original commands are and then use them in the same way that ordinary commands are used.Using alias, frequently-used commands can be invoked using a different, preferred term; and complex or commonly-used options can be used as the defaults for a given command.

Aliases persist for the current session. They can be loaded at login time by modifying the shell's .rc file. The invocation and usage of alias differs depending on the shell; see your shell's documentation for details.

 

OPTIONS

TAG DESCRIPTION
name Specifies the alias name.
command Specifies the command the name will be an alias for.

EXAMPLES

Example-1:

Creates the alias "list"  such that using the list  command will always display the output of "ls -lrt".

# alias list ='ls -lrt'

Now if we run commnad list , then the output will be of ls -lrt :

#list

output:

total 56
rw-r--r-- 1 8980 Nov 29 22:18 examples.desktop
drwxr-xr-x 2 4096 Nov 29 23:13 Desktop
drwxr-xr-x 2 4096 Nov 29 23:13 Videos
drwxr-xr-x 2 4096 Nov 29 23:13 Templates
drwxr-xr-x 2 4096 Nov 29 23:13 Public
drwxr-xr-x 2 4096 Nov 29 23:13 Pictures
drwxr-xr-x 2 4096 Nov 29 23:13 Music

Example-2:

Invoking alias with no arguments will display all currently aliased commands.

#alias

output:

alias list ='ls -lrt'

Here list is the shortcut/alias created for command ls -lrt.

Example-3:

Create an alias "ll" which will run ls with the options to display all files (-a) in a long list format (-l).

#alias ll ='ls -la'
Now if we run commnad ll , then the output will be of ls -la
#ll

output:
total 136
drwxr-xr-x 21 nubo nubo 4096 Dec 29 10:26 .
drwxr-xr-x 4 root root 4096 Dec 27 19:40 ..
drwxrwxr-x 6 nubo nubo 4096 Dec 7 22:03 Applications
-rw------- 1 nubo nubo 1428 Dec 5 02:25 .bash_history
-rw-r--r-- 1 nubo nubo 220 Nov 29 22:18 .bash_logout
------------------------------------------------
------------------------------------------------
------------------------------------------------
------------------------------------------------
drwxr-xr-x 2 nubo nubo 4096 Nov 29 23:13 Public
-rw------- 1 root root 1024 Nov 30 21:28 .rnd
drwxr-xr-x 2 nubo nubo 4096 Nov 29 23:13 Templates
drwxr-xr-x 2 nubo nubo 4096 Nov 29 23:13 Videos
-rw------- 1 nubo nubo 49 Dec 29 10:26 .Xauthority
-rw------- 1 nubo nubo 108 Dec 29 10:26 .xsession-errors
-rw------- 1 nubo nubo 108 Dec 27 19:02 .xsession-errors.old

Example-4:

The below four commands create aliases for quickly navigating to one, two, three, or four higher-level directories, respectively. For instance, after these alises are set, typing the command "..." would navigate up the directory hierarchy twice.

#alias ..='cd ..'
#alias ...='cd ../../'
#alias ....='cd ../../../'
#alias .....='cd ../../../../'

Example-5:

Creates the alias "port", which would run netstat to display all currently open network ports.

#alias port='netstat -tulanp'
# port

output:

(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.1.1:53 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:6633 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:6634 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:6635 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:6636 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:6637 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:6638 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:6639 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:6640 0.0.0.0:* LISTEN -
tcp 0 64 192.168.0.102:22 192.168.0.103:62383 ESTABLISHED -


Advertisements