Useful Linux commands

List of Linux commands useful every day.

Did you know that there are literally hundreds of Linux commands? The interesting thing is that most people only need to use a very small subset of these commands. Below is a list of Linux commands that breaks down some of the most commonly used commands by category.

System information

# Display Linux system information.
uname -a

# Display Kernel information.
uname -r

# View the version of Redhat that is installed.
cat /etc/redhat-release

# Display how long the system has been running and the load.

# Display the host name.

# View restart history.
last reboot

# Display the current date and time.

# Display the calendar of the month.

Material information

# Show kernel messages.

# Display CPU information.
cat /proc/cpuinfo

# Display memory information.
cat /proc/meminfo

# View PCI devices.
lspci -tv

# View USB devices.
lsusb -tv

# View DMI / SMBIOS (hardware information) from BIOS.

# Display sda disk information.
hdparm -i /dev/sda

# Perform a read speed test on the sda disk.
hdparm -tT /dev/sda

Activity monitor and statistics

# View and manage processes.

# Alternative to top.

# View processor-related statistics.
mpstat 1

# View virtual memory statistics.
vmstat 1

# Display input / output (IO) statistics.
iostat 1

# View the last 100 syslog messages (use /var/log/syslog for Debian based systems.).
tail 100 /var/log/messages

# Capture and display all packets on the eth0 interface.
tcpdump -i eth0

# Monitor all traffic on port 80 (HTTP).
tcpdump -i eth0 'port 80'

# List all open files on the system.

# List of files opened by the user.
lsof -u user

# Display free and used memory.
free -h

# Run "df -h", showing periodic updates.
watch df -h

Management is user information

# View the user and group IDs of your current user.

# Displays the last users who logged in to the system.

# Shows who is logged into the system.

# Show who's connected and what they're doing.

# Create a group named "test".
groupadd test

# Create an account named john, with a comment of "John Smith" and create the user's home directory.
useradd -c "John Smith" -m john

# Delete the John account.
userdel john

# Add the John account to the sales group.
usermod -aG vente john

Command on files and folders.

# List all files in a long (detailed) list format.
ls -al

# Display the current working directory.

# Create a directory.
mkdir directory

# Delete the file.
rm file

# Delete the directory and its contents recursively.
rm -r directory

# Force deletion of the file without asking for confirmation.
rm -f file

# Delete the directory recursively.
rm -rf directory

# Copy the file (file1 to file2).
cp fichier1 fichier2

# Recursively copy source_directory to the destination. If the destination exists, copy source_directory to destination, otherwise create destination with the contents of source_directory.
cp -r source_directory destination

# Rename or move the file (file1 to file2). If file2 is an existing directory, move file1 to the file2 directory.
mv file1 file2

# Create a symbolic link to the nameofthelink
ln -s /path/to/file nameofthelink

# Create an empty file or update the access and modification times of the file.
touch file

# View the contents of the file.
cat file

# Browse a text file.
less file

# Display the first 10 lines of the file.
head file

# Display the last 10 lines of the file.
tail file

# Display the last 10 lines of the file and "follow" the file as it changes.
tail -f file

Process management

# View your running processes.

# Displays all the processes currently running on the system.
ps -ef

# Display the process information for the process name.
ps -ef | grep processname

# End a process with the pid ID.
kill pid

# End processes with the name processname.
killall processname

# Start the program in the background.
program &

# Show programs that are stopped or in the background.

# Bring the most recent background program to the foreground.

# Bring program n to the foreground.
fg n


# Linux chmod example

U   G   W
rwx rwx rwx     chmod 777 filename
rwx rwx r-x     chmod 775 filename
rwx r-x r-x     chmod 755 filename
rw- rw- r--     chmod 664 filename
rw- r-- r--     chmod 644 filename

U = User
G = Group
W = World

r = Read
w = write
x = execute
- = no access


# Show all network interfaces and the IP address.
ifconfig -a

# Show address and details of eth0.
ifconfig eth0

# Find or check network driver and hardware settings.
ethtool eth0

# Send the ICMP echo request to the host.
ping host

# Display the whois information for the domain.
whois domain

# View DNS information for the domain.
dig domain

# Reverse lookup for IP_ADDRESS.

# Display the DNS IP address for the domain.
host domain

# Download the file

# Display of tcp and udp listening ports and corresponding programs.
netstat -nutlp

# See the number of connections per IP address
sudo netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

Archiving (Tar file)

# Create an archive.tar file containing the directory.
tar cf archive.tar directory

# Extract the contents of the archive.tar file
tar xf archive.tar

# Create a compressed tar file with gzip archive.tar.gz.
tar czf archive.tar.gz directory

# Extract a compressed tar file with gzip.
tar xzf archive.tar.gz

# Create a compressed tar file with bzip2 archive.tar.gz.
tar cjf archive.tar.bz2 directory

# Extract a tar file compressed with bzip2.
tar xjf archive.tar.bz2


# Search in a file.
grep pattern file

# Search the directory recursively.
grep -r pattern directory

# Search for files and directories by name.
locate name

# Find the files in /home/john that start with "prefix".
find /home/john -name 'prefix*'

# Look for files larger than 100MB in /home.
find /home -size +100M

Disk usage

# View free and used space on mounted file systems.
df -h

# Display free and used inodes on mounted file systems.
df -i

# View the sizes and types of disk partitions.
fdisk -l

# Show total disk usage outside current directory
du -sh


# To go up one level in the directory tree. (Change to the parent directory.)
cd ..

# Go to the $HOME directory

# Go to the /etc directory
cd /etc

Schedule tasks

# See scheduled tasks of the current user. crontab -l # Modify scheduled tasks of the current user. crontab -e # Modify scheduled tasks of another user. sudo crontab -e -u USERNAME # See scheduled tasks of all users. sudo getent passwd | cut -d: -f1 | perl -e'while(<>){chomp;$l = `crontab -u $_ -l 2>/dev/null`;print "$_\n$l\n" if $l}'


In Linux, there are several commands available, some command requires the installation of certain "package" and are available or have a variant depending on the distribution.

Other suggestions

Commandes Linux utiles

CentOS Linux Ubuntu

Liste de commandes Linux utile tous les jours.

Création d'une crontab

CentOS Linux Ubuntu

Tutoriel de création d'une tâche planifier sous Linux via l'utilisation de crontab.

Extensionner un disque

CentOS Linux Ubuntu

Tutoriel pour extensionner un disque ou partition sous Linux.

Copyright 2017-2020 © webO3 - all rights reserved