Walker News

Use Alias To Create Linux Command Shortcut

Majority of Apple fans prefer the graphical Mac OS than using its underlying Unix core; system administrators (particular Windows admin) keen on intuitive Linux Desktop and generally trying to avoid the “black and white” command console.

The reason of these is probably simple to understand – command interface requires users to memorize and type each of the commands precisely.
Otherwise, the system will not entertain any mistakes :-)

Thus, you’ll be happier with Linux command prompt only if you’re good with most Linux commands and its respective option switches!

But, it’s good to agree that the command prompt is sometimes much simple and efficient to get system work.

If there is situation where you can’t avoid to type out the long Linux command regularly, create an shortcut of it. The alias command is the trick!

Some examples of using the Linux alias command:
alias gsudo="sudo -l | grep --color=auto"

will set gsudo as the Linux command shortcut to highlight a given command in sudo -l report, i.e. gsudo tar to highlight the tar so that a user could easily confirm that the command is granted to his sudo access list (sudo -l).
alias ccls='export LS_COLORS="no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.btm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:"'

will set ccls as another Linux command shortcut that tweak $LS_COLORS environment variable to ligthen the colorized directory listing (i.e the ls command) in darker console.

If you’re frequently working on WordPress project in Linux environment, then the alias command will be really useful for setting up command shortcut that change path between wp-content/themes and wp-content/plugins directory. For example, these are the alias command shortcuts that I’ve setup in my VMware environment.
alias cwin='cd /var/www/html/walkernews/wp-includes'
alias cthe='cd /var/www/html/walkernews/wp-content/themes'
alias cplu='cd /var/www/htmlwalkernews/wp-content/plugins'

So, if anyone find Linux command console hard to use, tell him/her to use the alias to make a command shortcut!

Brief note about the Linux alias command:

1) To display or verify the command shortcuts that defined by alias command, just type alias or alias -p at the command prompt.

2) By default, there is a hidden file called .bashrc in each of the user’s home directory. You can define or set command shortcuts using the alias command here. The .bashrc file will be executed while the .bash_profile is executed as user login (i.e. the shortcuts will be ready whenever user login)

3) While the $HOME/.bashrc only available to individual users, the /etc/bashrc file can be used to define or set alias command shortcut for all users, i.e. globally!

Custom Search

  1. Get Linux Ls Command To Show File Timestamp In Detail Of Seconds 11-03-09@01:03

    […] –full-time -l mbox To make it even neat and easy to use, just create an Linux alias command as I do, mapping user-defined command name to the ls command and option […]

  2. Thyago 10-01-12@01:02

    Thank you, very usefull post! Made my life really easier with:
    alias ap-restart=’/etc/init.d/apache2 restart’ :)

2018  •  Privacy Policy