10 Lesser Known Effective Linux Commands


Linux is a powerful operating system that is widely used in the world of software development, web hosting, and cloud computing. Linux has many commands that can help you perform various tasks, but some commands are not commonly used or known to many people. These lesser-known commands can be very useful and save you time and effort. In this article, we will explore some of the effective but lesser-known Linux commands.

'rename' command

The 'rename' command is used to rename multiple files at once. The syntax for this command is as follows −

rename 's/oldname/newname/' files

Here, 'oldname' is the original name of the file, and 'newname' is the new name that you want to give to the file. For example, if you want to rename all files with the extension .txt in a directory to have the extension .md, you can use the following command −

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

This will rename all files with the extension .txt to have the extension .md.

'at' command

The 'at' command is used to schedule a task to run at a specific time. The syntax for this command is as follows −

at time

Here, 'time' is the time at which you want the task to run. For example, if you want to run a script called 'myscript.sh' at 2:30 PM, you can use the following command −

echo "/path/to/myscript.sh" | at 2:30 PM

This will schedule the script to run at 2:30 PM.

'history' command

The 'history' command is used to display a list of the commands that you have entered in the terminal. The syntax for this command is simply −

history

This will display a numbered list of the commands that you have entered. You can use the up and down arrow keys to navigate through the list. If you want to execute a command from the history list, you can simply type its number and press Enter.

'nc' command

The 'nc' command is used to establish a network connection with a remote host. The syntax for this command is as follows −

nc host port

Here, 'host' is the hostname or IP address of the remote host, and 'port' is the port number that you want to connect to. For example, if you want to connect to a remote host at IP address 192.168.1.100 on port 8080, you can use the following command −

nc 192.168.1.100 8080

This will establish a network connection with the remote host on port 8080.

'ps' command

The 'ps' command is used to display information about the currently running processes. The syntax for this command is as follows −

ps options

Here, 'options' are the various options that you can use to customize the output. For example, if you want to display a detailed list of all running processes, you can use the following command −

ps aux

This will display a detailed list of all running processes.

'find' command

The 'find' command is used to search for files and directories in a specified location. The syntax for this command is as follows −

find location options

Here, 'location' is the directory in which you want to search for files and directories, and 'options' are the various options that you can use to customize the search. For example, if you want to find all files in the current directory and its subdirectories that have the extension .txt, you can use the following command −

find . -name "*.txt"

This will search for all files in the current directory and its subdirectories that have the extension .txt.

'xargs' command

The 'xargs' command is used to build and execute commands from standard input. The syntax for this command is as follows −

command | xargs options

Here, 'command' is the command that you want to execute, and 'options' are the various options that you can use to customize the execution. For example, if you want to find all files in the current directory and its subdirectories that have the extension .txt and delete them, you can use the following command −

find . -name "*.txt" | xargs rm

This will find all files in the current directory and its subdirectories that have the extension .txt and delete them.

'tar' command

The 'tar' command is used to create and extract tar archives. The syntax for this command is as follows −

tar options file(s)

Here, 'options' are the various options that you can use to customize the archive, and 'file(s)' are the files that you want to include in the archive. For example, if you want to create a tar archive of all files in the current directory and its subdirectories that have the extension .txt, you can use the following command −

tar -czvf archive.tar.gz $(find . -name "*.txt")

This will create a tar archive called 'archive.tar.gz' of all files in the current directory and its subdirectories that have the extension .txt.

'df' command

The 'df' command is used to display information about the disk space usage on the system. The syntax for this command is as follows −

df options

Here, 'options' are the various options that you can use to customize the output. For example, if you want to display the disk space usage in human-readable format, you can use the following command −

df -h

This will display the disk space usage in human-readable format.

'free' command

The 'free' command is used to display information about the memory usage on the system. The syntax for this command is simply −

free

This will display a summary of the memory usage on the system, including the total amount of memory, the amount of memory that is currently in use, and the amount of memory that is free.

'watch' command

The 'watch' command is used to execute a command repeatedly and display the output in real-time. The syntax for this command is as follows −

watch options command

Here, 'options' are the various options that you can use to customize the output, and 'command' is the command that you want to execute repeatedly. For example, if you want to monitor the output of the 'ps' command in real-time, you can use the following command −

watch -n 1 "ps aux"

This will execute the 'ps aux' command every 1 second and display the output in real-time.

'split' command

The 'split' command is used to split a large file into smaller files. The syntax for this command is as follows −

split options input_file prefix

Here, 'options' are the various options that you can use to customize the splitting, 'input_file' is the file that you want to split, and 'prefix' is the prefix that you want to give to the resulting files. For example, if you want to split a file called 'bigfile.txt' into smaller files of 100 MB each with a prefix of 'part', you can use the following command −

split -b 100M bigfile.txt part

This will split the file 'bigfile.txt' into smaller files of 100 MB each with a prefix of 'part'.

Conclusion

In conclusion, Linux has many commands that can help you perform various tasks, but some commands are not commonly used or known to many people. These lesser-known commands can be very useful and save you time and effort. The above-mentioned commands are just a few examples of the effective but lesser-known Linux commands. Knowing and using these commands can make your Linux experience more efficient and productive.

Updated on: 27-Apr-2023

132 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements