Summery: In this article we are going to talk about 10 Linux Command Line Tricks that will help you to make your work easy.

Linux Command Line have many tricks that will help you to make your terminal work easy. So here are some tips and tricks that will help you to save lot of time while you are working on the terminal.

Tab Auto-completion

This is one of the most obvious yet very helpful feature available in most of the Linux command lines. As the name implies this will allow you complete a partially typed command by pressing the tab key in your keyboard. For example, let’s say you have a file named test.txt. you need to copy it from your current working directory to your Documents folder. You can start typing cp te and then press tab this will complete the name of the file as test.txt then type Doc and press tab. This will complete name of the destination folder. In this case it is Documents.

cp teTab ↹   DocTab ↹  

Also Read: 6 Best Themes for Linux Distributions 2019

Copying a file to the Current working directory

There is a file in /usr/share/wordlists/useranmes/small/alpha.txt Your current working directory is Documents/office/project/pentest/lab01/samples So let’s assume you need to copy that text file into your current working directory. You can do this task in three ways.

cp  /usr/share/wordlists/useranmes/small/alpha.txt Documents/office/project/pentest/lab01/samples

This is the longest way. You have to type the full file path of your destination. Instead of typing the full path of the destination, you can do the following.

cp /usr/share/wordlists/useranmes/small/alpha.txt `pwd`

In here instead of typing the full path of the destination we are using the pwd command inbetwwen backticks. pwd command is use to print the current working directory.

cp /usr/share/wordlists/useranmes/small/alpha.txt .

You can also use a dot to denote the current working directory.

Switch back to the last working directory

Let’s assume you were in the home directory of your system. For some reason you moved to /usr/share/wordlists/useranmes/small/ directory. Now you want come back to the previous directory. You can do this using a dash (-)

cd –
How to Switch back to the last working directory

Above command will take you to the previous directory that you’ve been.

Also Read: Linux File Permissions Explained

Running Multiple Command at same time in your terminal

For this you can use the semicolon (;) or ampersand (&) character. For example,

Command1; Command2; Command3
Command1 && command2

When you are using the ampersand (&) character to run multiple commands the second command will only run if the first command is was successful. But when you use semicolon (;) character to run multiple commands it will not check for the completion of the previous commands. Each and every command will run on their own. They will not wait for the previous commands to finish their business.

Using commands that you had used in the past (Reverse Search)

Imagine you have the following command

python -c ‘import pty; pty. Spawn(“/bin/bash”);’

You need to use this command 20 times per day. It would be a pain to type this command over and over again. To overcome this situation, you can use the reverse search option. To enter into the reverse search, you need to press Ctrl+R then start typing the command. Just like auto completion the previously typed command will popup. Then press enter to use the command.

Using commands that you had used in the past (Reverse Search)

Moving to the beginning and End of a line in terminal without using arrow keys.

Use Ctrl+A to move to the beginning of a line. Or else you can use the home key.

Use Ctrl+E to move to the end of a line. Or else you can use the end key.

Copy and Paste in Linux Terminal

Different terminals have different ways of doing this. But in general, you can do this as follows.

The standard keyboard short cuts to copy and paste is Ctrl+c and Ctrl+v respectively. But when it comes to linux terminals we cant use any of those short cuts.

In Linux you can use Ctrl+shift+c to copy and Ctrl+shift+v to paste.

Empty a file with hundreds of lines

Imagine you have log file with hundreds of logs saved in to. If you need to empty the file content without deleting the actual log file, you can use the bellow trick to empty the file within a second.

> filename
Empty a file with hundreds of lines in Linux

Run Your Last Command as Root

One of the most common mistake we all do is forgetting thesudo in front of a command which required root permissions to run. Imagine you accidentally typed “apt install net-tools“. If you are a low privileged user in the box you need sudo permissions to run this command. If you forgot the sudo part at the beginning you don’t have re type the command again. Just type sudo !!

How to Run Your Last Command as Root

Record your Command Line Session

Imagine you are new to Linux. You practice the command line every day. While you are practicing the command line you can use the script command. This command will save all of your typing to a file named typescript. Once you type exit, all of your commands will be written to that file so you can review them later.

How to Record your Command Line Session


Leave a Reply

Your email address will not be published. Required fields are marked *