Top Linux Command Line Tips and Tricks
Last Updated :
21 Mar, 2022
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.
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"
Apropos Command2. 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
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 Command4. 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
ll Command6. 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 -
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
xargs Command8. 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 "Geeksforgeeks" text. So here is the command we can use:
grep "Geeksforgeeks" ~/Documents/*.txt
Grep Command9. 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 !!
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:
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.
Similar Reads
SED command in Linux | Set 2
We have discussed some of the SED command options in Sed Command in Linux/Unix with examples SED is used for finding, filtering, text substitution, replacement and text manipulations like insertion, deletion search, etc. It's a one of the powerful utilities offered by Linux/Unix systems. We can use
8 min read
Nice and Renice Command in Linux with Examples
In Linux, managing process priority is crucial for optimizing system performance, especially in environments where multiple processes compete for CPU resources. The nice and renice commands allow users to adjust the scheduling priority of processes, influencing how the Linux kernel allocates CPU tim
3 min read
Useful and time saving bash commands in Linux
There are multiple helpful Bash scripts that will make your Linux terminal experience fast and seamless. In Linux, you can automate and execute numerous day-to-day tasks using plain commands â without laying hands on the GUI. These bash script examples assist you in automating file operations, list
5 min read
ls Command in Linux
The ls command is one of the most used commands in the Linux terminal to display the files and directories or path in the terminal. So, using the ls command is a basic skill for navigating the Linux file system, handling files, and managing directories.What is the ls Command in LinuxThe ls command i
10 min read
7 Tips and Tricks to Learn Programming Faster
One of the common and basic questions among students or someone who wants to learn code is "How can I learn to code fast and make a career as a programmer?". Whether you are a student, fresher or experienced person trying to switch your job in programming you will definitely try to find tips and tri
7 min read
Linux System Monitoring Commands and Tools
Monitoring the performance and health of a Linux system is essential for maintaining its stability and optimizing resource utilization. Linux provides a variety of commands and tools to facilitate system monitoring, enabling administrators to track key metrics, identify potential issues, and ensure
6 min read
Basic Shell Commands in Linux: Complete List
Anyone using Linux should become an expert in the essential shell commands, as they form the backbone of working with the Linux terminal. These commands enable you to navigate the system, manage files, handle processes, and configure settings effectively.The Linux shell serves as an interface for us
5 min read
How to Build Your Own Commands in Linux?
Linux is one of the most widely used open-source operating systems which supports both GUI as well as CLI. It has been widely used all over the world since its first distribution launched on September 17, 1991, by Linus Torvalds. It is widely known for its command-line operations. We have been using
6 min read
xargs command in Linux with examples
xargs is a Unix command which can be used to build and execute commands from standard input. Importance:Some commands like grep can accept input as parameters, but some commands accept arguments, this is a place where xargs came into the picture. Syntax of `xargs` command in Linuxxargs [options] [co
5 min read
chattr and lsattr commands in Linux with examples
In the world of Linux, managing file permissions and attributes is crucial for maintaining a secure and organized system. Two powerful commands that help control file and directory attributes are 'chattr' and 'lsattr'. These commands are essential for administrators and advanced users who need to pr
8 min read