Saturday, November 16, 2024
Google search engine
HomeGuest BlogsTop Linux Command Line Tips and Tricks

Top Linux Command Line Tips and Tricks

Linux is a great OS that offers multiple options for simplifying tasks. It has everything you need for working more efficiently, whether a command-line or a GUI. However, many people don’t know the Linux command line’s short tricks and end up being stuck in complex tasks. An interface (text-based) through which you communicate with your system’s OS. That’s called a Command-Line. You can easily navigate to files and folders in your system and perform the task.

Top-Linux-Command-Line-Tips-and-Tricks

Linux Command Line offers various techniques to play with folders. If you want to learn Top Linux Command Line Tips and Tricks, make sure you read this blog entirely. We have divided the following information into several parts. The first few are basics, others are directory-related, and the rest are advanced tips. Let’s read Tips and Tricks for Linux Commands: 

1. Identify the Correct Command

Sometimes, you want to perform a specific task but don’t know the correct command. In this case, you can use apropos to identify the right command for your task. For example, we want to copy files but don’t know the correct commands. That’s why we have executed the following command in the command line:

apropos "copy files" 
Correct Command

Apropos Command

2. Execute Multiple Commands at Once

You can run multiple commands simultaneously by using ‘;‘ between them. For example, we are removing GeeksForGeeks_1.txt and renaming the GeeksForGeeks_2.txt through the rm command and mv command:

rm -v GeeksForGeeks_1.txt; mv GeeksForGeeks_2.txt gfg.txt
Multiple Commands at Once

Execute Multiple Commands at Once (;)

You can use ‘&&‘ to ensure that the following command is only executed if the previous one was successful. Here we update and upgrade the system but want to run the commands one by one:

sudo apt update && sudo apt upgrade

Execute Multiple Commands at Once (&&)

3. History of the Executed Commands

Using the history command, you can view all previously executed commands. Run the below command in the terminal:

history 
History of Executed Commands

History Command

4. Keyboard Shortcuts for the Linux Terminal

There are multiple types of keyboard shortcuts to complete the tasks quickly. Here are some helpful keyboard shortcuts for beginners and experienced users:

Keyboard Shortcuts Description
CTRL, ALT, and T It can open the new terminal window.
CTRL, and  A You can move the cursor to the start of the line.
CTRL, and C It can stop the currently executed command.
CTRL, and L It clears the terminal screen.
CTRL, and D It can close the terminal window.
CTRL, and E You can use it for moving the cursor to the end of the line.
ALT, and B You can use it for moving the cursor a word backward.
ALT, and F You can use it for moving the cursor a word forward.
CTRL, and U  It can remove the complete command (line).
CTRL, and  T You can change the current character to the previous one.
ALT, and  T You can change the current word with the previous one.
CTRL, SHIFT, and C It can copy the line in the terminal
CTRL, SHIFT, and V You can paste the line in the terminal

5. List the Contents of the Directory

Most Linux users use the ls -l command to list the directory’s contents. However, you can do the same using the ll command in Linux:

ll
Contents of Directory

ll Command

6. Return to the Last Working Directory

After moving from one directory path to another, you want to return to the first one, then use the cd – command. This command can redirect you to the last working directory. Hence, it can save you time to type the directory path again.

cd -
Last Working Directory

cd – Command

The image above shows that the first working directory is “Pictures” and the second is “Documents.” Using the cd – command, we moved from “Pictures” to “Documents.” 

7. Copy Files into Different Directories

Linux offers a way to copy files from its terminal using the cp command. If users want to copy a file, then they will use the following command:

cp ~/Folder/File_Name.txt ~/Folder_1
cp ~/Folder/File_Name.txt ~/Folder_2
cp ~/Folder/File_Name.txt ~/Folder_3

Instead of using the cp command multiple times, you can use the xargs command to copy a file into various directories. For example, we copy gfg.txt from Documents to Pictures, Music, Videos directories. So here is the basic syntax of xargs:

echo ~/Folder_1/ ~/Folder_2/ ~/Folder_3/ | xargs -n 1 cp -v ~/Folder_4/File_Name.txt
Copy Files to Different Directories

xargs Command

8. Identify Files Containing a Unique Text

If you are looking for a file containing specific text, you can use the grep command. For example, we are finding the files that have “Geeksforneveropen” text. So here is the command we can use: 

grep "Geeksforneveropen" ~/Documents/*.txt
Identify Files having Unique Text

Grep Command

9. Use the Previous Command in the Current One

Suppose you are working on the Linux terminal and want to use the same command repeatedly, then it becomes a little irritating to type the same commands again and again. Therefore, you can use it!! instead of the previous command as it will automatically re-execute the last command.

sudo !!
Using Previous Commands in Current One

sudo !!

10. Schedule a Shutdown Time for the System

You can schedule a timer for shutting down the system. For example, we want to shut down a system at 13:00, so here is the basic command:

Scheduling Shutdown Time for System

Timer Command

These were the top Linux command line tips and tricks that you can try today. All these tips are based on our experience, which we try regularly. Therefore, you can also try these tricks to improve your productivity while working on Linux. 

Last Updated :
21 Mar, 2022
Like Article
Save Article


Previous

<!–

8 Min Read | Java

–>


Next


<!–

8 Min Read | Java

–>

Share your thoughts in the comments

RELATED ARTICLES

Most Popular

Recent Comments