Though the Graphical Interface in Linux now-a-days is getting better
and better to become more and more mature, more of the flexibility in
Linux over other Graphical Operating Systems is still more easily gained
using Command-Line. Desktop users are generally annoyed or afraid (may
be) of using command line for their purposes. But this article may help
them to make Linux Command Line more easier.
Due to more flexibility offered by it, Command-Line, in Linux, is made available in different ways.
There are several commands that can be used in Linux for different purposes but before that lets see how using command line can be made easy so that any user can use command-line very easily. For many people command-line on Linux becomes very complicated, especially when they need to write long commands and repeat those commands them at some point of time. Below we will see some shortcuts and you might also come across some commands that you are not aware about but you need not worry about that as we will discuss many commands in the due course of time.
Here are some shortcuts available in Linux Command-Line :
Tab Key : is used for different purposes. Pressing it for 1 time or twice have two different purposes to serve.
History command - using previously used commands
Alias – Defining shortcuts for long commands
Due to more flexibility offered by it, Command-Line, in Linux, is made available in different ways.
- In Current generation Linux we have access to command line in various ways. we can either open command line console or open a command line terminal being in Graphical console it self. lets see how
- In Linux there are different consoles running at different tty which can be accessed using Ctrl+Alt+F1………………..Ctrl+Alt+F12
- On most Linux Distributions including Ubuntu, Fedora, CentOS, Redhat, Suse, etc. Graphical console is by default available on 7th Console which means if we press Ctrl+Alt+F7 from any console we can get back to Default Graphical Console.
- In above example we can see tty3 that is 3rd console which can be invoked by pressing Ctrl+Alt+F3. By default tty1 to tty6 are command-Line consoles. we can log into command line console with any username and password that we use at graphical login screen. We can login with different users on different consoles.
- To access command-line from Graphical Console in any Gnome based Linux Distribution like Ubuntu, we can open Gnome Terminal from using menu which is generally available in Applications (Menu) → Accessories → Terminal. Or in any Linux Distribution we can press Alt+F2 to invoke Run Dialog box and type gnome-terminal and press enter to start command-line terminal in Graphical console.
- Those Command-Line Terminals are also known as pseudo terminals and we can open more than 1 pseudo terminals at a time. Those terminals are named pts1, pts2 subsequently.
There are several commands that can be used in Linux for different purposes but before that lets see how using command line can be made easy so that any user can use command-line very easily. For many people command-line on Linux becomes very complicated, especially when they need to write long commands and repeat those commands them at some point of time. Below we will see some shortcuts and you might also come across some commands that you are not aware about but you need not worry about that as we will discuss many commands in the due course of time.
Here are some shortcuts available in Linux Command-Line :
Tab Key : is used for different purposes. Pressing it for 1 time or twice have two different purposes to serve.
- Tab key for completing the command
- When we are typing any command we can just type starting letters of the command and press tab key to complete those commands. Now if there are more commands starting with same letters then pressing the Tab key twice we can get a list of all commands starting with the character that we have typed
- See example as below : In below example I am trying to invoke firefox (web-browser) and I want to type firefox. But instead I will type fir and press tab key.
- After pressing the Tab key you will see that firefox command is completed automatically.
- Tab key for Listing all available commands starting with same letters
- In the same way If I press f and then the tab key it will not do any thing but if I press Tab key twice it will display all the commands starting with f. We can short list by typing more and more initial letters of the command.
History command - using previously used commands
- This command can be used to display last 1000 commands that we have issued till now.
- In the screen below we can see the out-put of history with several commands listed. All of those commands are starting with a number which is command no.
- These command nos. can be used to invoke specific command. Eg. if we invoke no. 1245 it will execute command ping google.com.
- To invoke any previously used command we can write it starting with ! (exclamation) mark. Eg. !1245 with execute command no. 1245 that is ping google.com.
- Ctrl+r can be issued from command line this will help us to repeat any command that has been issued in past very easily.
- For using it at command line press Ctrl+R
- This will change your command prompt as below
- Then start typing the letters of any word in the command that was
issued previously. The command will be displayed at the command
prompt.
Here I am finding a command where I used “del”
- The command displayed in above example is “route del default gw 192.168.5.1 which I previously used to delete default gateway.
- At this stage if we want to find other command containing same
letters just press Ctrl+r again and it will take to commands issued
even more previously.
Like in example below you may notice the change in IP address. This command was given even more previously than the command that was first displayed.
Alias – Defining shortcuts for long commands
- Alias command can be used for creating shortcuts of long commands.
- In example below we can see that a shortcut with name “delgw” is to be created for a long command like “route del default gw 192.168.5.1”. Press enter and continue the creation.
- Now when I want to use a command “route del default gw 192.168.5.1” I can use delgw instead.
- This way every command that makes command-line complicated can have a defined alias.
- Note : Commands created with alias command are only for current
session that means if you reboot your OS all those aliases created will
be deleted.
There is certainly a way out to make aliases permanent. We can add our commands to a file from where our system will execute all those alias commands whenever the system reboots. - The file that can hold your alias command for permanent use is available at /home/<username>/.bashrc
- To edit this file we can issue following command
- gedit /home/<username>/.bashrc
- Note :
- <username> here stands for current user with which you are logged in.
- if you want to make permanent aliases for root user replace /home/<username> with /root. i.e. you will have to edit the file at /root/.bashrc
- gedit is a text editor.
- Between gedit and /home/<username>/.bashrc there should always be a space.
- Example below shows how to edit /home/enjay/.bashrc
- here enjay is the user in whose .bashrc I want to make permanent aliases
- alias delgw=’route del default gw 192.168.5.1′ is the line added at the end of the file
- Finally save the file and permanent alias will be activated at the next boot.