amazon media file explorer download upload index folder image licenses menu widget Play Pause profile-settings more dots-two-horizontal dots-two-vertical more-vertical pending google-plus hangouts facebook instagram whatsapp spotify telegram twitter vine renren rss youtube twitch vimeo flickr dribble behance deviantart 500px steam github soundcloud skype reddit linkedin lastfm delicious stackoverflow pinterest xing flattr foursquare yelp World

Creating Command Aliases in GNU/Linux (Command Shortcuts)

As time goes on, you'll need to be super productive with the way you use commands in GNU/Linux, and one example is utilizing alias.

Using alias allows you to create an additional equivalent name for a command, for example, you can simplify commands to one word or few letters, say you want to simplify sudo apt install to only 'install', you use the following command:

alias install="sudo apt install"

Entering the above command will provide no output, but behind the scene, a new command 'install' is now an alias(equals) to 'sudo apt install'

Verify the alias by running the 'alias' command:

1. All Aliases

You should see the alias you just created, you'll also see additional aliases in the output, If you are using Ubuntu, it has some alias created by default, for example, l is the same as ls.

Now when you want to install any packages, you can simply do the following:

install nginx

Super simple right! you don't have to type 'sudo apt install nginx', if you are way too lazy, you can simplify it further:

alias i="sudo apt install"

Now by adding 'i <package name>, you can install anything pretty fast with less typing.

One thing to note before we go further is that, when you exit your terminal window, your aliases are wiped out, ouch!. Fortunately, you can retain them by editing the .bashrc file, this file is present in your home directory
and is read every time you start a new Terminal session.

We can add an alias in there, but it is recommended we add it into a new file: ~/.bash_aliases, this makes it easier to maintain.

Once you are done, reload your bashrc file using:

source ~/.bashrc

Now, that you understand alias, let's see some cool example:

Clear Screen by Typing 'c'

alias c=clear

Jump Into Apache Log Folder

alias apl="cd /var/log/apache2"

We can be creative with the above command, why not jump into the folder, and also list the files in there? See the below command:

alias apl="cd /var/log/apache2 && ls"

This would replace the first one because I am using the same name 'apl'

Jump Into Nginx Log Folder and List All the Files in the Folder

alias ngl="cd /var/log/nginx && ls"

View the Top Ten Cpu Consuming Processes:

alias cpu10='ps auxf | sort -nr -k 3 | head -10'

View the Top Ten Ram Consuming Processes:

alias mem10='ps auxf | sort -nr -k 4 | head -10'

Jump To Users Home Directory

alias home="cd ~"

Removing alias

To remove alias, you use the 'unalias' keyword, so, to remove alias whos name is home, I'll do:

unalias home

The best way to come up with a aliases, is to think of commands you use on a regular basis, and simplify it, take a look at your bash history for commands you use.


Related Post(s)

  • How To Access Windows 10 Drive/Folder in VirtualBox

    To access Windows drive or folder in your Guest OS, you first of all, install VirtualBox guest utilities: sudo apt-get install virtualbox-guest-utils You then Add a shared folder by going into: Setti

  • Send Mail with Attachment Using Mutt in GNU/Linux

    Mutt is a powerful text&#x2d;based mail client for Unix/Linux operating systems. It features color support, message threading, MIME support...

  • Using Pageant To Automatically Authenticate SSH key in Putty

    I can't count how many times I have typed my ssh key passphrase whenever my ssh connection times out, it is so annoying and repetitive. Well, thanks to the putty pageant, you can do that seamlessly.

  • Installing WP-CLI In a GNU/Linux Server

    WP-CLI is a command-line interface for WordPress. It can also be used with ClassicPress, as they are no differences in their usage, maybe just minimal if you are updating or downloading new ClassicPr

  • How To Send Mail To Multiple Addresses Using (mailx)

    In this guide, you'll learn a couple of ways you can send mail to multiple addresses using mailx. mailx is a utility program for sending and receiving mail. I assume you already have mailx command, i

  • Mounting and Unmounting Cloud Storage With (Rclone) in GNU/Linux

    Ever wondered if you could mount your preferred cloud storage as a virtual drive on your system? Thanks to Rclone, you can mount and access different kinds of cloud storage from a file manager, I'll