The Linux command line attracts most Linux enthusiasts. A normal Linux user generally possesses a vocabulary of roughly 50-60 commands to carry out their day-to-day tasks.

Linux commands and their switches remain the most valuable treasure for a Linux user, shell script programmer, and administrator. There are some Linux commands that are lesser-known yet very useful and handy, irrespective of whether you are a novice or an advanced user.

This article aims to shed light on some of the lesser-known Linux commands that will surely help you handle your desktop/server more efficiently.

1. sudo !! command

The sudo !! command is a useful shortcut that allows you to repeat the last command with sudo privileges.

For example, running the command without specifying the sudo command will give you a permission denied error. So, you don’t need to rewrite the whole command again just put !! will grab the last command.

apt update
sudo !!
Repeating Commands with Superuser Privileges
Repeating Commands with Superuser Privileges

2. Python Command

The command python3 -m http.server 8000 starts a simple HTTP server in Python, which serves files from the current directory over HTTP.

For example, the below command generates a simple web page over HTTP for the directory structure tree and can be accessed at port 8000 in the browser till an interrupt signal is sent.

python3 -m http.server 8000
Simple HTTP Server in Python
Simple HTTP Server in Python

3. mtr Command

Most of us are familiar with ping and traceroute. How about combining the functionality of both commands into one with mtr command.

In case mtr is not installed on your machine, you can install it using your system package manager.

sudo apt install mtr         [On Debian, Ubuntu and Mint]
sudo yum install mtr         [On RHEL/CentOS/Fedora and Rocky/AlmaLinux]
sudo emerge -a sys-apps/mtr  [On Gentoo Linux]
sudo apk add mtr             [On Alpine Linux]
sudo pacman -S mtr           [On Arch Linux]
sudo zypper install mtr      [On OpenSUSE]    
sudo pkg install mtr         [On FreeBSD]

Now run the mtr command to start investigating the network connection between the host google.com.

mtr google.com
Network Diagnostics and Performance Monitoring
Network Diagnostics and Performance Monitoring

4. Ctrl+x+e Command

The Ctrl+x+e command is very useful for administrators and developers. For day-to-day tasks, administrators often need to open an editor by typing `vi`, `vim`, `nano`, etc.

However, for an instant editor from the terminal, you can use the press Ctrl-x-e from the terminal prompt and start working in the editor.

Start Text Editor in Terminal
Start Text Editor in Terminal

5. nl Command

The nl command is used to number lines of files or standard input. It’s useful for adding line numbers to the output, which can help in various tasks like reviewing or debugging text files.

Suppose you have a text file named example.txt with the following content (cat command – list content of a file):

fedora 
debian 
arch 
slack 
suse

You can use the nl command to number the lines of this file:

nl example.txt
Adding Line Numbers to File
Adding Line Numbers to File

6. shuf Command

The shuf command is used to shuffle lines of text files or input, which is useful for randomizing the order of lines in a file or generating random permutations.

Suppose you have a file named list.txt with the following content:

Ubuntu
Debian
Fedora
RockyLinux
AlmaLinux
RHEL Linux
OpenSUSE

You can use the shuf command to shuffle the lines of this file:

shuf list.txt
Shuffle Lines of Text Files
Shuffle Lines of Text Files

7. ss Command

The ss command stands for “socket statistics“, which is used to investigate sockets and displays information similar to the netstat command.

However, ss can show more detailed TCP and state information than other tools.

ss -tuln
Show Network Statistics
Show Network Statistics

8. last Command

The “last” command shows the history of last logged-in users. This command searches through the file “/var/log/wtmp” and shows a list of logged-in and logged-out users along with tty’s.

last
Show Last Logged Users
Show Last Logged Users

9. curl ifconfig.me

The curl ifconfig.me command is used to retrieve your public IP address from the ifconfig.me service, which is a quick and convenient way to check your public IP without needing to visit a website.

curl ifconfig.me

49.36.109.114

10. tree Command

The tree command is used to display a hierarchical view of directories and files in a tree-like format, which is useful for visualizing the structure of directories and their contents.

tree
Show Directory Structure
Show Directory Structure

11. pstree Command

The pstree command prints a tree-like diagram of currently running processes, showing how processes are related to each other in a hierarchical manner.

pstree 
Show Processes Structure
Show Processes Structure

In this article, we explored some lesser-known yet highly useful Linux commands that can enhance your command-line proficiency and streamline your workflows.

Read Also:

Similar Posts