DEV Community

Hussain
Hussain

Posted on

Linux Command Lines That You Should Know!

Have you ever encountered frustration running commands in the terminal to get one job done? You use plenty of commands to get one job and then you get frustrated, These are the command lines that will lessen your frustration and get you more productive on the task, So, are you ready to be Pro in Linux? let’s start with emptying the file!

Just Empty Don’t Delete!

If you just want to empty the file without deleting the file itself, you can use this command:

> filename

Use alias to mistypos

Sometimes it must have happened to you that you always mistype a command and you have to retype it again, So no need to retype it again just use alias in Linux!

For example, you might often mistype echo as ecoh, then just put an alias in your bashrc file like this:

alias ecoh=echo

less to read files

Using cat to see the contents of the file is not a good option, because it displays the whole text and then you struggle to see the script from the start,

Using less command to read files is better option.

less path_to_file

You can search for terms inside less, move by page, display with line numbers etc.

Move to beginning or end of line

This has happened to me many times, whenever I’m working with a long command, I used to use arrow keys to get to the beginning, but my nightmare ended when I found out this!

You can also Home and End keys here of course but alternatively, you can use Ctrl+A to go to the beginning of the line and Ctrl+E to go to the end.

Accidental Terminal Freeze!

Accidently used Ctrl+S on the terminal? Don’t worry, you don’t have to close the terminal, not anymore. Just use Ctrl+Q and you can use the terminal again.

ctrl+Q

Reverse Search

This would have happened to you when doing long CTFS and you were working for some time and then you had to use the same command as you used earlier in the terminal, you can use reverse search to search for the command that you used earlier the in the history!

Just use the keys ctrl+r to initiate reverse search and type some part of the command. It will look up the history and will show you the commands that match the search term.

ctrl+r search_term

By default, it will show just one result. To see more results matching your search term, you will have to use ctrl+r again and again. To quit reverse search, just use Ctrl+C.

Switch back to the last working directory

Whenever you end up being in the wrong directory, and you then cd to the last directory that you were working on, so no need for that use this to switch back to the last working directory!

cd -

Running multiple commands in one single command

Don’t wait for the first command to complete to run the second after that, You can use the ‘;’ separator for this purpose. This way, you can run a number of commands in one line.

command_1; command_2; command_3
Reference: It’s Foss

Top comments (0)