10 Lesser Known Useful Linux Commands


Linux is an operating system that has become increasingly popular over the years. It's known for its stability, security, and flexibility, making it a favorite among developers and system administrators. One of the great things about Linux is that it comes with a lot of powerful commands that can make your life easier. In this article, we'll be discussing some of the lesser-known but useful Linux commands.

Watch Command

The watch command is a simple but powerful command that allows you to watch the output of a command or script every few seconds. This is useful when you want to monitor a process or command and see how it's progressing over time. Here's an example −

watch -n 1 'df -h'

This will display the disk usage of your system every second. The -n option specifies the interval (in seconds) at which the command should be executed.

Cal Command

The cal command is a simple command that displays a calendar. This command can be very useful when you want to quickly check what day of the week a certain date falls on. Here's an example −

cal 04 2023

This will display the calendar for April 2023.

Tmux Command

The tmux command is a terminal multiplexer that allows you to run multiple terminal sessions within the same window. This is useful when you want to work on multiple tasks simultaneously. Here's an example −

tmux new -s mysession

This will create a new session named "mysession". You can then switch between different sessions using the tmux command.

Stat Command

The stat command is a command that displays file or filesystem status. This command can be very useful when you want to quickly check the size, permissions, and creation time of a file. Here's an example −

stat my_file.txt

This will display the status of the file "my_file.txt".

Fuser Command

The fuser command is a command that identifies processes that are using a particular file or directory. This command can be very useful when you want to identify which processes are using a certain file or directory. Here's an example −

fuser -v /home/user/myfile.txt

This will display the processes that are currently using the file "myfile.txt".

Du Command

The du command is a command that displays the disk usage of a file or directory. This command can be very useful when you want to quickly check how much disk space a file or directory is using. Here's an example −

du -sh /home/user/mydirectory

This will display the size of the directory "mydirectory" in a human-readable format.

Nohup Command

The nohup command is a command that allows you to run a command or script in the background even if you close the terminal. This command can be very useful when you want to run a long-running process that you don't want to be interrupted by a terminal session closing. Here's an example −

nohup python myscript.py &

This will run the Python script "myscript.py" in the background and save the output to a file called "nohup.out".

Netstat Command

The netstat command is a command that displays network-related information such as active connections, listening ports, and routing tables. This command can be very useful when you want to quickly check network activity on your system. Here's an example −

netstat -tulpn

This will display all the active TCP and UDP connections on your system along with the process ID of the process that is using the connection.

Lsof Command

The lsof command is a command that displays the list of open files and the processes that have opened them. This command can be very useful when you want to identify which processes are using a particular file or directory. Here's an example −

lsof /home/user/myfile.txt

This will display the processes that are currently using the file "myfile.txt".

Tcpdump Command

The tcpdump command is a command-line tool that allows you to capture network packets and display them in real-time. This command can be very useful when you want to monitor network traffic on your system. Here's an example −

sudo tcpdump -i eth0

This will capture all network packets that pass through the eth0 network interface.

Grep Command

The grep command is a command that allows you to search for specific text patterns in files or output. This command can be very useful when you want to quickly find a specific piece of information in a large file or output. Here's an example −

cat my_file.txt | grep "error"

This will display all lines in the file "my_file.txt" that contain the word "error".

Rsync Command

The rsync command is a command that allows you to synchronize files and directories between different systems or local directories. This command can be very useful when you want to backup or transfer files between systems. Here's an example −

rsync -avz /home/user/documents/ remoteuser@remotehost:/backup/

This will synchronize the contents of the directory "/home/user/documents/" to the remote system at the "/backup/" directory.

Free Command

The free command is a command that displays the amount of free and used memory in the system. This command can be very useful when you want to quickly check the memory usage of your system. Here's an example −

free -h

This will display the amount of free and used memory in a human-readable format.

Mkdir Command

The mkdir command is a command that allows you to create a new directory. This command can be very useful when you want to quickly create a new directory. Here's an example −

mkdir my_directory

This will create a new directory called "my_directory".

W Command

The w command is a command that displays information about the currently logged-in users on the system. This command can be very useful when you want to quickly check who is logged in to the system. Here's an example −

w

This will display information about the currently logged-in users on the system, including the time they logged in and what they are currently doing.

Chmod Command

The chmod command is a command that allows you to change the permissions of files or directories. This command can be very useful when you want to restrict or grant access to certain files or directories. Here's an example −

chmod 755 my_script.sh

This will change the permissions of the file "my_script.sh" so that the owner has full access and everyone else can read and execute the file.

Kill Command

The kill command is a command that allows you to terminate a process. This command can be very useful when you want to stop a process that is causing problems or using too many system resources. Here's an example −

kill 1234

This will terminate the process with the ID "1234".

Ps Command

The ps command is a command that displays information about the processes running on the system. This command can be very useful when you want to check the status of a process or identify a process that is causing problems. Here's an example −

ps aux | grep "my_process"

This will display all processes that contain the word "my_process".

History Command

The history command is a command that displays a list of previously executed commands in the terminal. This command can be very useful when you want to quickly access a command that you previously executed. Here's an example −

history | tail -n 10

This will display the last 10 commands that you executed in the terminal.

Tar Command

The tar command is a command that allows you to create and extract compressed archive files. This command can be very useful when you want to compress and backup files or transfer files between systems. Here's an example −

tar -czvf my_archive.tar.gz /home/user/documents/

This will create a compressed archive file called "my_archive.tar.gz" that contains the contents of the directory "/home/user/documents/".

Updated on: 27-Apr-2023

249 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements