10 Interesting Linux Command Line Tricks and Tips

10 Interesting Linux Command Line Tricks and Tips

Linux is the most popular open-source operating system in the world. It is powerful and flexible, but it can be intimidating for new users. The Linux command line is particularly daunting, with hundreds of commands, flags, and options to learn. In this article, we will share 10 interesting Linux command line tricks and tips to help you become a more effective Linux user.

1. Creating a directory and its parent directories at the same time

Sometimes, you may need to create a directory along with its parent directories. You can use the ‘-p’ option to achieve this. The ‘-p’ option creates parent directories when necessary.

The below command creates a directory named ‘test’ along with its parent directories:

mkdir -p /home/user/newdirectory/test

2. Renaming multiple files all at once

Renaming multiple files individually can be a tedious task. However, you can use the ‘rename’ command to rename multiple files in one go.

The below command renames all the files with the extension .txt to .md:

rename 's/.txt/.md/' *.txt

3. Using Wildcards

Wildcards are used to represent one or more characters in a command. For example, ‘*’ represents any number of characters, and ‘?’ represents a single character.

The below command copies all the files with the extension .txt to the folder named ‘backup’:

cp *.txt backup/

4. The ‘top’ command

The ‘top’ command displays the current CPU and memory usage of the system, along with the process statistics.

Enter the below command to run the ‘top’ command:

top

5. The ‘watch’ command

The ‘watch’ command is used to run a command repeatedly and monitor its output.

The below command runs the ‘ls’ command every 2 seconds and displays its output:

watch -n 2 ls

6. Setting an alias

An alias is a short name or abbreviation for a command. You can set an alias to save time and reduce typing.

The below command sets an alias ‘l’ for the ‘ls’ command:

alias l='ls -CF'

7. Using the ‘history’ command

The ‘history’ command displays a list of the last executed commands.

Enter the below command to display the last 10 executed commands:

history 10

8. Using the ‘find’ command

The ‘find’ command searches for files and directories in a specified location.

The below command finds all the files with the extension .txt in the ‘/home/user/documents’ directory and its subdirectories:

find /home/user/documents -name '*.txt' -type f 

9. Displaying the disk space usage

The ‘df’ command displays the disk space usage on the file system.

Enter the below command to show the disk space usage on your system:

df -h

10. The ‘tree’ command

The ‘tree’ command displays the directory structure in a tree-like format.

Enter the below command to display the directory structure of the current directory:

tree

Conclusion

These are 10 interesting Linux command line tricks and tips that can help you become a more effective Linux user. Using these commands and techniques can save you time, make your workflow more streamlined, and increase your productivity. The Linux command line is a powerful tool, but it can take some time and practice to master. With these tricks and tips, you can take your Linux skills to the next level.

Like(0)