Linux is a powerful operating system. It is used by many web developers. Here are some useful Linux commands that every web developer should know.

Most of other article talks about the basic Linux commands i.e. ls, cd, mkdir, rm, mv, cp, cat, grep, etc. In this article, I will talk about some advanced Linux commands to improve your productivity.

1. find

The find command is used to search for files in a directory hierarchy. It is a powerful command that can be used to find files based on their name, size, type, permissions, etc.

find . -name <file_name>
# find all files with name "index.html"
find . -name "index.html"

# Find files by size
find . -size <size>

#Find files by type
find . -type <type>

# Find files by permissions
find . -perm <permissions>

   

2. mkpasswd

The mkpasswd command is used to generate encrypted password. It is used to create a password for a user.

mkpasswd -m sha-512 <password>

   

3. ssh-keygen

It is used to generate SSH keys. It is used to create a public and private key pair. The public key is used to encrypt the data and the private key is used to decrypt the data.

ssh-keygen -t rsa -b 4096 -C "

   

4. ssh-copy-id

It is used to copy the public key to the remote server. It is used to authenticate the user without entering the password.

ssh-copy-id -i <public_key> <user>@<host>

   

5. ssh

It is used to connect to a remote server. It is used to connect to a remote server using SSH protocol.

ssh <user>@<host>

   

6. scp

It is used to copy files between the local and remote server. It is used to copy files between the local and remote server using SSH protocol.

scp <file> <user>@<host>:<destination>

   

7. rsync

It is used to synchronize files between the local and remote server. It is used to synchronize files between the local and remote server using SSH protocol.

rsync -avz <file> <user>@<host>:<destination>

   

Monitoring tools

1. htop

htop is an interactive process viewer for Unix systems. It is a text-mode application (for console or X terminals) and requires ncurses. It aims to be a better ‘top’.

  sudo apt install htop

  htop

   

2. iotop

iotop shows a list of processes currently doing disk I/O. It can show you which process is reading or writing to disk and how much data is being transferred.

sudo apt install iotop

iotop

   

3. lsof

It’s a command-line utility that lists information about files that are open by processes. It can be used to find out which process is using a particular file or port. Its a short form of list open files.

# List all open files
lsof -i :<port_number>

# List all open files by a process
lsof -p <process_id>

# List all open files by a user
lsof -u <user_name>

# List all open files by a user and a process
lsof -u <user_name> -p <process_id>

   

4. netstat

It’s a command-line utility that displays network connections for Transmission Control Protocol (TCP), User Datagram Protocol (UDP), and Transmission Control Protocol/Internet Protocol (TCP/IP) network protocols. It can be used to find out which process is using a particular port.

# List all open ports
netstat -tulpn

# List all open ports by a process
netstat -tulpn | grep <process_id>

# List all open ports by a user
netstat -tulpn | grep <user_name>

# List all open ports by a user and a process
netstat -tulpn | grep <user_name> | grep <process_id>

   

5. ps

It’s a command-line utility that reports a snapshot of the current processes. It can be used to find out which process is using a particular port.

# List all processes
ps -ef

# List all processes by a user
ps -ef | grep <user_name>

# List all processes by a user and a process
ps -ef | grep <user_name> | grep <process_id>

   

6. kill

It’s a command-line utility that sends a signal to a process or a group of processes. It can be used to kill a process.

# Kill a process
kill <process_id>

# Kill a process by a user
kill -9 $(ps -ef | grep <user_name> | grep -v grep | awk '{print $2}')

# Kill a process by a user and a process
kill -9 $(ps -ef | grep <user_name> | grep <process_id> | grep -v grep | awk '{print $2}')

   

7. ncdu

It’s a disk usage analyzer with an ncurses interface. It can be used to find out which directory is using the most disk space.

# Install ncdu
sudo apt install ncdu

# Run ncdu
ncdu

   

Networking

1. nmap

nmap is a free and open source utility for network exploration or security auditing. Many systems and network administrators also find it useful for tasks such as network inventory, managing service upgrade schedules, and monitoring host or service uptime.

# Install nmap
sudo apt install nmap

# Scan a host
nmap <host>

# Scan a host with a specific port
nmap -p <port_number> <host>
#example
nmap -p 80 google.com

# Scan a host with a specific port range
nmap -p <port_number_start>-<port_number_end> <host>
#example
nmap -p 80-100 <host>

   

2. curl

curl is a command-line tool for transferring data using various protocols. It is used in command lines or scripts to transfer data. It is also used in cars, television sets, routers, printers, audio equipment, mobile phones, tablets, settop boxes, media players and is the internet transfer backbone for thousands of software applications affecting billions of humans daily.

# Install curl
sudo apt install curl

# Download a file
curl -O <url>

# Download a file with a specific name
curl -o <file_name> <url>

   

3. wget

wget is a free software package for retrieving files using HTTP, HTTPS, FTP and FTPS the most widely-used Internet protocols. It is a non-interactive commandline tool, so it may easily be called from scripts, cron jobs, terminals without X-Windows support, etc.

# Install wget
sudo apt install wget

# Download a file
wget <url>

   

4. dig

dig is a network administration command-line tool for querying Domain Name System (DNS) name servers. It is used to retrieve resource records from DNS name servers.

# Install dig
sudo apt install dnsutils

# Query a DNS server
dig <domain_name>

# Query a DNS server with a specific type
dig <domain_name> <type>
#example
dig google.com A

   

5. host

host is a command-line network utility for querying the Domain Name System (DNS) to obtain domain name or IP address mapping or for any other specific DNS record.

# Install host
sudo apt install dnsutils

# Query a DNS server
host <domain_name>

# Query a DNS server with a specific type
host -t <type> <domain_name>
#example
host -t A google.com

   

6. nslookup

nslookup is a computer network administration command-line tool available for many operating systems for querying the Domain Name System (DNS) to obtain domain name or IP address mapping or for any other specific DNS record.

# Install nslookup
sudo apt install dnsutils

# Query a DNS server
nslookup <domain_name>

# Query a DNS server with a specific type
nslookup -type=<type> <domain_name>
#example
nslookup -type=A google.com

   

7. traceroute

traceroute is a computer network diagnostic tool for displaying the route (path) and measuring transit delays of packets across an Internet Protocol (IP) network.

# Install traceroute
sudo apt install traceroute

# Trace a route
traceroute <domain_name>

   

8. ping

ping is a computer network administration software utility used to test the reachability of a host on an Internet Protocol (IP) network. It measures the round-trip time for messages sent from the originating host to a destination computer that are echoed back to the source.

# Install ping
sudo apt install iputils-ping

# Ping a host
ping <host>

   

9. netcat

netcat is a computer networking utility for reading from and writing to network connections using TCP or UDP. The command is designed to be a dependable back-end that can be used directly or easily driven by other programs and scripts.

# Install netcat
sudo apt install netcat

# Send a message to a host
echo <message> | nc <host> <port>

# Receive a message from a host
nc -l <port>