We learned so may linux commands from previous screwlinux articles. So today we are giving you one of the mostly used 10 linux tips and tricks. 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.
Yeah. That’s fine. From this article we discuss most of the linux tips and tricks you should know, some sort of pretty, tiny commands. But they will be very useful. Go through the 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
- !! : This will run the last command in the history. According to the above image, !! 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.
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.
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.
In this article, we have mentioned 10 useful tips for you. You can refer more with man pages. Practice more.
Above 10 linux tips and tricks are one of the most usefull commands and shortcut you need to know, because these knowledge saves alot of time when you are working.
Useful resources :