Introduction
Unlock the full potential of your Linux system with this comprehensive guide to essential Linux commands. Whether you’re an experienced administrator or a beginner, mastering these commands is vital for efficient server management, script writing, and troubleshooting. This tutorial will walk you through the most frequently used and powerful commands for file management, process control, user access, network configuration, and system debugging.
You’ll learn over 50 must-know Linux commands that will elevate your skills and turn you into a Linux power user. From basic tasks to advanced operations, these commands will become your go-to tools for efficiently managing and troubleshooting your system.
Prerequisites
To follow along with this tutorial, you’ll need a running Linux environment. We will be using an Ubuntu server for the demonstration, but these commands will work on any modern Linux distribution.
For this tutorial, we recommend setting up a virtual machine (VM) using VirtualBox or another virtualization tool. If you don’t already have a Linux system set up, you can follow a guide to install Ubuntu on VirtualBox or any other virtual machine platform of your choice.
Top 50 Essential Linux Commands Every Regular User Should Know
- pwd – Prints the current working directory, showing your current location in the filesystem.
- cd – Used to change directories, allowing you to navigate through the filesystem.
- ls – One of the most commonly used commands in Linux to list the contents of a directory.
- mkdir – Command to create new directories, organizing your file system.
- touch – Creates an empty file or updates the timestamp of an existing file.
- mv – Move or rename files and directories in Linux, a versatile command for file management.
- cp – Similar to
mv
, but for copying files or directories without moving them. - rm – Deletes files or directories, removing them from the filesystem.
- ln – Creates symbolic links (shortcuts) to files or directories, allowing easier access.
- clear – Clears the terminal screen, providing a clean workspace.
- cat – Displays the contents of a file directly in the terminal, useful for quick views.
- echo – Prints a string of text to the terminal, often used in scripts or command-line output.
- less – Displays content in a paged format, useful for reading long files without scrolling.
- man – Opens the manual page for a command, offering detailed information on how it works.
- uname – Displays basic information about the operating system, including the kernel version.
- whoami – Reveals the currently logged-in user, helpful for user-related tasks.
- top – Displays live information about active processes, including their system resource usage.
- ps – Displays information about currently running processes on your system.
- kill and killall – Terminates active processes, either by process ID or by name.
- df – Displays information about disk space usage and available storage.
- chmod – Changes the permissions of files or directories, controlling who can access or modify them.
- chown – Changes the ownership of files or directories, assigning them to a specific user or group.
- tar – Used for compressing or extracting files from archive files like
.tar.gz
or.tar.bz2
. - grep – Searches for specific patterns or strings within files, making it easy to find information.
- head – Displays the top part of a file, usually the first few lines.
- tail – Shows the last few lines of a file, often used for viewing logs.
- diff – Compares two files and shows the differences between them.
- cmp – Compares two files byte by byte and determines if they are identical.
- comm – Combines the features of
diff
andcmp
by displaying common lines, unique lines, and differences. - sort – Sorts the contents of a file, outputting them in a specific order.
- export – Sets environment variables, which can affect the behavior of processes and commands.
- zip – Compresses files into a zip archive for easy sharing or storage.
- unzip – Extracts files from a zip archive, restoring the original files.
- ssh – Securely connects to remote systems over a network, enabling remote management.
- service – Starts or stops system services, such as web servers or databases.
- wget – Downloads files from the internet directly to your system using the command line.
- ufw – Simple firewall management tool for managing firewall rules and security settings.
- iptables – Provides low-level control for configuring firewalls, often used alongside other utilities.
- apt, pacman, yum, rpm – Package managers for various Linux distributions, helping you install, update, and remove software.
- sudo – Executes commands with superuser privileges, allowing administrative tasks.
- cal – Displays a calendar directly in the terminal, useful for quick reference.
- alias – Creates custom command shortcuts to simplify complex or frequently used commands.
- dd – Used for low-level copying of files, often for creating bootable USB drives or backups.
- whereis – Locates the binary, source, and manual pages of a command, helping you find its files.
- whatis – Provides a brief description of a command, helping you understand its purpose.
- useradd and usermod – Adds new users or modifies existing user data, helping with user management.
- passwd – Creates or updates the password for a user account, ensuring system security.
- mount – Mounts file systems to access storage devices or remote file systems.
- ifconfig – Displays information about network interfaces and their associated IP addresses.
- traceroute – Traces the network route to a destination, showing each hop along the way.
File and Directory Commands
Command | Description | Example |
---|---|---|
ls | List directory contents. | ls |
cd | Change directory. | cd /path/to/directory |
pwd | Show current directory. | pwd |
mkdir | Create a new directory. | mkdir new_directory |
rmdir | Remove an empty directory. | rmdir empty_directory |
rm | Delete files or directories. | rm file.txt |
touch | Create an empty file. | touch new_file.txt |
cp | Copy files or directories. | cp file.txt /path/to/destination |
mv | Move or rename files. | mv file.txt /path/to/new_location |
cat | Display file contents. | cat file.txt |
nano / vim | Edit files in terminal. | nano file.txt |
find | Search for files in a directory hierarchy. | find . -name "file.txt" |
grep | Search text using patterns. | grep "pattern" file.txt |
tar | Archive and compress files. | tar -cvf archive.tar file1.txt file2.txt |
df | Show disk usage of file systems. | df |
du | Show directory/file size. | du -sh /path/to/directory |
chmod | Change file permissions. | chmod 755 file.txt |
chown | Change file owner. | chown user:group file.txt |
mount | Mount a filesystem. | mount /dev/sdb1 /mnt |
umount | Unmount a filesystem. | umount /mnt |
Networking Commands
Command | Description | Sample Usage |
---|---|---|
ping | Test connectivity to a host. | ping google.com |
ifconfig / ip a | Display network interfaces. | ifconfig or ip a |
netstat / ss | Show network connections. | netstat -tuln or ss -tuln |
wget | Download files via HTTP/FTP. | wget http://example.com/file.zip |
curl | Transfer data using URL syntax. | curl -O http://example.com/file.zip |
nc (Netcat) | Network debugging and data transfer. | nc -zv 192.168.1.1 80 |
tcpdump | Capture and analyze network packets. | tcpdump -i eth0 |
iptables | Configure firewall rules. | iptables -A INPUT -p tcp --dport 22 -j ACCEPT |
traceroute | Trace the path packets take to a network host. | traceroute example.com |
nslookup | Query DNS to obtain domain name or IP address mapping. | nslookup example.com |
ssh | Securely connect to a remote host. | ssh user@example.com |
Process and System Monitoring Commands
Command | Description | Example Command |
---|---|---|
ps | Show running processes. | ps aux |
top | Dynamic process viewer. | top |
htop | Enhanced version of top. | htop |
kill | Send a signal to a process. | kill <PID> |
killall | Kill processes by name. | killall <process_name> |
uptime | System uptime and load. | uptime |
whoami | Current logged-in user. | whoami |
env | Display environment variables. | env |
strace | Trace system calls of a process. | strace -p <PID> |
systemctl | Manage systemd services. | systemctl status <service_name> |
journalctl | View system logs. | journalctl -xe |
free | Display memory usage. | free -h |
vmstat | Report virtual memory statistics. | vmstat 1 |
iostat | Report CPU and I/O statistics. | iostat |
lsof | List open files by processes. | lsof |
dmesg | Print kernel ring buffer messages. | dmesg |
User and Permission Management Commands
Command | Description | Example Command |
---|---|---|
passwd | Change user password. | passwd <username> |
adduser / useradd | Add a new user. | adduser <username> or useradd <username> |
deluser / userdel | Delete a user. | deluser <username> or userdel <username> |
usermod | Modify user account. | usermod -aG <group> <username> |
groups | Show group memberships. | groups <username> |
sudo | Execute commands as root. | sudo <command> |
chage | Change user password expiry information. | chage -l <username> |
id | Display user identity information. | id <username> |
newgrp | Log in to a new group. | newgrp <group> |
File Transfer and Synchronization Commands
Command | Description | Example Command |
---|---|---|
scp | Securely copy files over SSH. | scp user@remote:/path/to/file /local/destination |
rsync | Efficiently sync files and directories. | rsync -avz /local/directory/ user@remote:/path/to/destination |
ftp | Transfer files using the File Transfer Protocol. | ftp ftp.example.com |
sftp | Securely transfer files using SSH File Transfer Protocol. | sftp user@remote:/path/to/file |
wget | Download files from the web. | wget http://example.com/file.zip |
curl | Transfer data from or to a server. | curl -O http://example.com/file.zip |
Text Processing Commands
Command | Description | Example Command |
---|---|---|
awk | Pattern scanning and processing. | awk '{print $1}' file.txt |
sed | Stream editor for filtering/modifying text. | sed 's/old/new/g' file.txt |
cut | Remove sections from lines of text. | cut -d':' -f1 /etc/passwd |
sort | Sort lines of text. | sort file.txt |
grep | Search for patterns in text. | grep 'pattern' file.txt |
wc | Count words, lines, and characters. | wc -l file.txt |
paste | Merge lines of files. | paste file1.txt file2.txt |
join | Join lines of two files on a common field. | join file1.txt file2.txt |
head | Output the first part of files. | head -n 10 file.txt |
tail | Output the last part of files. | tail -n 10 file.txt |
Shell Utilities and Shortcuts Commands
Command | Description | Example Command |
---|---|---|
alias | Create shortcuts for commands. | alias ll='ls -la' |
unalias | Remove an alias. | unalias ll |
history | Show previously entered commands. | history |
clear | Clear the terminal screen. | clear |
reboot | Reboot the system. | reboot |
shutdown | Power off the system. | shutdown now |
date | Display or set the system date and time. | date |
echo | Display a line of text. | echo "Hello, World!" |
sleep | Delay for a specified amount of time. | sleep 5 |
time | Measure the duration of command execution. | time ls |
watch | Execute a program periodically, showing output fullscreen. | watch -n 5 df -h |