10 Linux tips for easy Linux Administration

Have you ever noticed a moment when someone doing tasks with some simple terminal commands which took a long time for you to do. And you feels like to asking from yourself "Wow, How did he do that very easily ?"  Then you think yourself, If i also could do like that.

Go through this complete article and make yourself to hear a Wow from someone else. It will make you very comfortable.

1) Execute a previous command

Normally every command that we type is storing in a file named ".bash_history" inside of your home directory. To view the the past typed commands we can use the command history in your terminal. It will list all the commands that you typed.

There are some options we need to know

    # history
    !! : This will run the last command in the history.
    !! will rerun the history command.
    !<number> : If you need to run a specific command in the history. Assume you need to run first command which means tree command according to the above image. It should be !1.
    history | grep <keyword> : This will search the keyword in history.
    UP keyboard button press also will take you to the past history commands.

2) How to clear the terminal

Use command "clear" to clear the terminal window.

3) Use Tab auto completion

Use Tab keyboard press to auto complete the commands. 

4) Changing directories

cd - : Go to the last directory where you were.
cd ~ : Go to the home directory
cd : Go to your home directory ( same as above command )
cd .. : Go to the previous location. Means one step back.

5) Run multiple commands in one single line

You can do this just putting a semi colon ";" in between commands. Like below.

command_1 ; command_2 ; command_3

With this you can run several commands in one single line without waiting to be completing other commands. Means, second commands don't want to wait till first command gets completed. It saves time.

6) Run multiple commands in one single line, but finishing one after second.

command_1 && command_2 && command_3

Here, the command waits for the completion of it's previous command. This is useful to trigger if the commands are getting fail. If one commands is failing, next command will not be run.

7) Search and run previous commands without referring history.

Ctrl + r + <search keyword>

This is a very useful command that will be helped you a lot. You just press the control key and r letter in the keyboard. Then enter the search keyword you need to find. Then it will show you the most nearest command suits for your keyword in the history. It searches from bottom to top on history. To keep finding the required command, just press Ctrl + r in the keyboard and enter when you found.

8) Vim Cheat sheet

:w : Save the file
:wq : Save the file and quite
:q : Quite the file without saving
:wq! : Forcefully save and quite the file
:q! : Forcefully quite the file without saving
yy  : yank ( Copy a line to the text editor )
p : Paste the copied content into the text editor.
dd : Delete a line
x : Delete a character
/<keyword> : search for a keyword in text file
gg : Go to the first line of the text editor
G : Go to the last line of the text editor
:set num : View the document showing line numbers
i : Insert mode

9) Displaying the files with more lines

Use command "less" to view the files which have more lines. Use arrow UP and DOWN in the keyboard to go though the file.

less <filename>

10) Make a file empty without deleting.

Use echo  > filename command. This will send a blank character to that file and will replace every content in the file.