Top 100 Linux Commands You Should Know: With Syntax, Examples, and Output for Beginners to Experts

Posts

Linux is a powerful, open-source operating system that forms the backbone of countless servers, cloud platforms, security infrastructures, and development environments. Unlike graphical user interfaces found in systems like Windows or macOS, Linux offers a more flexible and powerful way to interact with the system through its command line interface. Mastery of Linux commands is essential for professionals such as system administrators, cybersecurity analysts, developers, and network engineers.

The command line provides unparalleled control, allowing users to perform tasks more efficiently and script repetitive operations. It also consumes fewer system resources, making it ideal for remote access and headless environments. Whether a user is setting up a server, managing a network, auditing security, or writing software, understanding core Linux commands will significantly enhance productivity and capabilities.

This guide is designed to help both beginners and experienced users get comfortable with essential Linux commands. It is divided into four comprehensive parts. Each part includes commonly used commands, explanations, usage examples, and expected outputs to facilitate hands-on learning.

This first part will focus on commands related to file and directory management, which is foundational to using any Linux system effectively.

File and Directory Management in Linux

Managing files and directories is one of the most basic and essential tasks in any operating system. In Linux, everything is treated as a file, including devices, directories, and configurations. Understanding how to navigate the filesystem, create or delete files, and manage directories is crucial for any Linux user.

Viewing Files and Directories with ls

The ls command is used to list the contents of a directory. It displays files, directories, and symbolic links within a specified path. It is often used with options to show hidden files or display additional information like file permissions and sizes.

Command example:
ls /home/user

Expected output:
Documents Downloads Pictures

This command shows the contents of the /home/user directory. To include hidden files, use ls -a. To display detailed file information, use ls -l.

Printing the Current Directory with pwd

The pwd command stands for print working directory. It shows the full path of the current directory the user is in. This is helpful for navigation and scripting purposes.

Command example:
pwd

Expected output:
/home/user

It helps confirm the exact location within the filesystem, especially when switching between directories frequently.

Changing Directories with cd

The cd command is used to change the current working directory. It allows the user to navigate the filesystem quickly.

Command example:
cd /var/log

This command moves the user into the /var/log directory. You can go back one level using cd .. or return to the home directory with just cd.

Creating Directories with mkdir

The mkdir command is used to create new directories. It is often used when organizing files or setting up environments for projects or services.

Command example:
mkdir testfolder

This command creates a new directory named testfolder in the current location. To create nested directories, use the -p option.

Removing Directories with rmdir

The rmdir command deletes an empty directory. If the directory contains files, the command will not work.

Command example:
rmdir testfolder

If testfolder is empty, it will be deleted. To remove non-empty directories, use the rm command with the -r flag.

Deleting Files and Folders with rm

The rm command is used to remove files and directories. It is a powerful tool and should be used with caution as deleted files are not moved to a recycle bin.

Command examples:
rm file.txt
rm -r foldername

The first command deletes file.txt. The second command recursively deletes the folder and its contents. Use the -f option to force deletion without prompts.

Creating Empty Files with touch

The touch command creates an empty file if it does not exist. It can also be used to update the timestamp of an existing file.

Command example:
touch notes.txt

This command creates a file named notes.txt in the current directory. It is commonly used to initialize new configuration files or logs.

Copying Files and Directories with cp

The cp command is used to copy files and directories. It supports various options for recursive copying, preserving permissions, and providing verbose output.

Command example:
cp file1.txt backupfile.txt

This command copies file1.txt to a new file named backupfile.txt. To copy directories, use the -r option.

Moving and Renaming Files with mv

The mv command is used for moving and renaming files or directories. It is often used when organizing files or changing filenames.

Command example:
mv oldname.txt newname.txt

This command renames oldname.txt to newname.txt. It can also move files to another directory if a path is specified.

Finding Files and Directories with find

The find command searches for files and directories based on criteria such as name, type, size, or modification time. It is one of the most versatile search tools in Linux.

Command example:
find /home -name “*.txt”

This command searches all subdirectories in /home for files with a .txt extension. Other useful options include -type, -mtime, and -exec for running commands on matched files.

Viewing and Editing File Content

Viewing and editing files from the command line is an essential skill for administrators and developers. Whether you are reading log files, editing configuration files, or writing shell scripts, the following commands provide efficient tools for interacting with file content.

Viewing File Content with cat

The cat command is used to display the contents of a file on the terminal. It can also be used to concatenate multiple files or redirect output to another file.

Command example:
cat file.txt

This command displays the entire contents of file.txt. For large files, consider using more or less instead.

Paging Through Files with more

The more command displays the content of a file one screen at a time. It is helpful when working with large files.

Command example:
more largefile.txt

This allows users to scroll through the file by pressing Enter or Space. It provides a basic interface for reading long documents.

Interactively Viewing Files with less

The less command is similar to more but more advanced. It allows both forward and backward navigation through a file.

Command example:
less config.log

This opens the file in an interactive viewer. Use the arrow keys or PgUp/PgDn to scroll. Press q to quit.

Viewing the Start of a File with head

The head command displays the first few lines of a file. By default, it shows the first ten lines.

Command example:
head data.csv

Use the -n option to specify the number of lines to show. This is useful for previewing file structure.

Viewing the End of a File with tail

The tail command shows the last few lines of a file. It is especially useful for monitoring logs.

Command example:
tail data.csv

Use tail -f filename to monitor a file in real time as it updates. This is helpful for troubleshooting services and watching live logs.

Editing Files with nano

The nano editor is a simple, easy-to-use text editor that runs in the terminal. It is ideal for quick edits to configuration or text files.

Command example:
nano script.sh

This opens script.sh in the nano editor. Use keyboard shortcuts for saving and exiting, such as Ctrl+O and Ctrl+X.

Editing Files with vi

The vi editor is a powerful, modal text editor available on nearly all Unix-based systems. It is preferred by many advanced users for its speed and capabilities.

Command example:
vi index.html

Press i to enter insert mode, Esc to exit it, and :wq to save and quit. Although the learning curve is steep, vi is extremely efficient once mastered.

Understanding System Information and Monitoring in Linux

Monitoring and retrieving system information in Linux is essential for ensuring stability, security, and performance. Whether you are a system administrator maintaining uptime on a production server or a developer checking hardware specs, the Linux command line provides a powerful set of tools to get real-time insights into the system.

In this section, we will explore a set of commands that help users understand the system’s operating environment, monitor resource usage, and gain insight into performance metrics such as memory, CPU, disk, and network usage. These tools are vital in identifying bottlenecks, diagnosing problems, and optimizing performance.

Each command listed below will include its purpose, usage, and example output where relevant. Mastering these commands equips users with the knowledge needed to keep a system healthy and responsive.

Displaying System Information

Getting System Details with uname -a

The uname command is used to print system information. The -a option provides a full overview, including kernel name, version, hardware name, and operating system.

Command example:
uname -a

Expected output:
Linux hostname 5.15.0-105-generic x86_64 GNU/Linux

This output shows that the system is running on a Linux kernel version 5.15, with a 64-bit architecture. uname without options will only display the kernel name.

Monitoring Running Processes

Viewing Active Processes with top

The top command displays real-time information about running processes, including CPU and memory usage. It provides a dynamic view that updates periodically.

Command example:
top

This interface shows a list of processes sorted by CPU usage, including PID, user, memory usage, and more. Press q to exit. Use h for help within the top interface.

Using htop for Interactive Process Monitoring

htop is a more user-friendly and interactive alternative to top. It offers color-coded output, process trees, and easier navigation.

Command example:
htop

This tool must be installed separately on some systems. It allows users to scroll through processes, kill them with a keypress, and sort by various metrics using function keys. Use arrows to navigate and F10 to quit.

Checking System Uptime and Users

Checking System Uptime with uptime

The uptime command shows how long the system has been running, along with the number of users and average system load.

Command example:
uptime

Expected output:
14:32:18 up 2 days, 3:41, 3 users, load average: 0.01, 0.05, 0.06

This output includes the current time, uptime duration, user count, and system load averages over 1, 5, and 15 minutes. It is helpful in assessing system stability and performance over time.

Identifying the Logged-In User with whoami

The whoami command prints the username of the currently logged-in user. It is particularly useful in scripts and permission checking.

Command example:
whoami

Expected output:
john

This confirms the active user session and helps avoid permission errors when running administrative commands.

Displaying System Hostname with hostname

The hostname command shows or sets the system’s network name. It identifies the machine on the local network or in a multi-host environment.

Command example:
hostname

Expected output:
webserver1

To set a new hostname, administrative privileges are required. Use hostnamectl set-hostname newname for persistent changes on modern systems.

Monitoring Memory and Disk Usage

Viewing Memory Usage with free -h

The free command shows the amount of used and free memory in the system. The -h flag makes the output human-readable, using units like MB and GB.

Command example:
free -h

Expected output:
total used free shared buff/cache available
Mem: 7.6G 1.2G 5.4G 115M 1.0G 6.1G
Swap: 2.0G 0B 2.0G

This breakdown includes total, used, and available RAM, as well as swap usage. It helps users understand how much memory is available and how resources are being allocated.

Checking Disk Usage with df -h

The df command shows disk space usage on mounted filesystems. The -h flag formats the sizes in a human-readable format.

Command example:
df -h

Expected output:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 20G 28G 42% /

This output shows the size, used space, and free space of each partition. Monitoring disk usage is crucial to prevent system crashes caused by full filesystems.

Measuring Directory Size with du -sh

The du command estimates file and directory space usage. The -s flag summarizes the total size, while -h makes it human-readable.

Command example:
du -sh folder/

Expected output:
120M folder/

This command is useful when trying to determine which directories are consuming the most space, especially during cleanup tasks or storage audits.

Advanced System Performance Metrics

Monitoring System Stats with vmstat

The vmstat command reports information about processes, memory, paging, block IO, and CPU usage. It provides a snapshot of overall system performance.

Command example:
vmstat

Expected output:
procs ———–memory———- —swap– —–io—- -system– ——cpu—–
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 112548 15492 490812 0 0 1 1 33 67 1 0 98 1 0

This table shows values such as running processes, free memory, swap activity, I/O operations, and CPU time breakdowns. It is often used for performance tuning and identifying resource bottlenecks.

Managing Software Packages in Debian and Ubuntu Systems

In Linux, package management refers to the process of installing, updating, upgrading, configuring, and removing software packages. Debian-based distributions such as Ubuntu use the Advanced Package Tool system, commonly accessed using commands like apt and dpkg. These tools simplify software management by automatically resolving dependencies and streamlining the installation process.

Understanding how to use package management commands is essential for maintaining a secure and efficient Linux system. These commands allow system administrators and developers to quickly deploy software, ensure that applications are up to date, and resolve any issues related to installed packages.

In this section, you will learn how to perform common package management tasks using apt and dpkg, two of the most commonly used tools on Debian and Ubuntu systems.

Updating and Upgrading Packages

Refreshing the Package List with apt update

The apt update command refreshes the package index from all configured repositories. This is the first step before installing or upgrading any software to ensure the system has the latest package metadata.

Command example:
apt update

Expected output:
Get:1 ubuntu focal InRelease [265 kB]
Fetched 12.5 MB in 3s (4,208 kB/s)
Reading package lists… Done

This command does not install or upgrade packages; it only updates the local database. It should be run regularly to keep the package information current.

Upgrading Installed Packages with apt upgrade

The apt upgrade command installs the latest versions of all packages currently installed on the system. It uses the updated package list to determine which packages need to be upgraded.

Command example:
apt upgrade

Expected output:
The following packages will be upgraded:
openssl libssl1.1 libc-bin
3 upgraded, 0 newly installed, 0 to remove

It is common to run apt update followed by apt upgrade in sequence to keep the system up to date. Use the -y option to confirm all prompts automatically during upgrade.

Installing and Removing Packages

Installing New Packages with apt install

The apt install command is used to install one or more software packages from the repository. It also resolves and installs any required dependencies automatically.

Command example:
apt install nmap

Expected output:
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
liblinear4
After this operation, 4,390 kB of additional disk space will be used.
Do you want to continue? [Y/n]

After confirmation, the selected package and its dependencies will be installed and ready to use. You can also install multiple packages in a single command by separating them with spaces.

Removing Installed Packages with apt remove

The apt remove command uninstalls a package but leaves its configuration files on the system. This is useful when you want to remove a program but preserve its settings for future use.

Command example:
apt remove nmap

Expected output:
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following packages will be removed:
nmap
After this operation, 3,500 kB disk space will be freed.
Do you want to continue? [Y/n]

To remove the configuration files as well, use apt purge instead of apt remove. This is helpful when completely uninstalling software.

Working with Installed Packages Using dpkg

Listing Installed Packages with dpkg -l

The dpkg -l command displays a list of all installed packages on the system. It includes the name, version, and a short description of each package.

Command example:
dpkg -l

Expected output:
ii bash 5.0-6ubuntu1 amd64 GNU Bourne Again SHell
ii curl 7.68.0-1ubuntu2 amd64 command line tool for transferring data
ii nmap 7.80+dfsg1-2 amd64 The Network Mapper

The ii in the first column indicates the package is installed and configured properly. You can pipe this output into grep to search for specific packages, such as dpkg -l | grep nmap.

Installing a .deb Package with dpkg -i

The dpkg -i command installs a local .deb file. This is commonly used for installing packages downloaded manually rather than from a repository.

Command example:
dpkg -i chrome.deb

Expected output:
Selecting previously unselected package google-chrome-stable.
Preparing to unpack chrome.deb …
Unpacking google-chrome-stable …
Setting up google-chrome-stable …

If any dependencies are missing, the installation may fail. To resolve them, run apt install -f afterward to automatically fix and install required dependencies.

Fixing Broken Installations

Resolving Dependencies with apt install -f

The apt install -f command attempts to fix broken dependencies. It is useful after manually installing packages using dpkg, which does not handle dependencies by itself.

Command example:
apt install -f

Expected output:
Reading package lists… Done
Correcting dependencies… Done
The following packages were automatically installed and are no longer required:
libappindicator1 libindicator7
The following additional packages will be installed:
libnss3

This command scans the system for incomplete installations and attempts to repair them by downloading and installing the necessary packages.

Removing Unused Packages

Cleaning Up with apt autoremove

The apt autoremove command removes packages that were automatically installed as dependencies but are no longer needed. This helps keep the system clean and reduces disk space usage.

Command example:
apt autoremove

Expected output:
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following packages will be removed:
libllvm11 libqt5core5a libqt5widgets5
After this operation, 150 MB disk space will be freed.

This command is often run after uninstalling large software suites or upgrading software that no longer relies on certain libraries.

Understanding Networking and User Management in Linux

Linux offers a rich set of commands for networking and user management, both of which are crucial for maintaining secure, functional, and connected systems. Networking tools help users test connectivity, retrieve information about network interfaces, diagnose problems, and transfer data. Meanwhile, user and group management commands are essential for managing access, security, and permissions on multi-user systems.

In this final section, you will learn the most important commands used to manage network settings and users in Linux environments. These tools are fundamental to any administrator, ethical hacker, or power user who needs to monitor, troubleshoot, or control system access and connectivity.

Networking Commands in Linux

Testing Connectivity with ping

The ping command is used to test the reachability of a host across an IP network. It sends ICMP echo request packets and displays the response time.

Command example:
ping google.com

Expected output:
PING google.com (142.250.185.78) 56(84) bytes of data.
64 bytes from 142.250.185.78: icmp_seq=1 ttl=114 time=25.3 ms

The output includes the response time in milliseconds and packet loss statistics. Use Ctrl+C to stop the command.

Viewing Network Interfaces with ifconfig

The ifconfig command displays or configures a system’s network interfaces. It shows information such as IP address, netmask, and MAC address.

Command example:
ifconfig

Expected output:
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255

ifconfig is deprecated on some distributions but still widely used. For modern systems, the ip command is recommended.

Displaying IP Addresses with ip a

The ip a command is a modern replacement for ifconfig. It displays detailed information about network interfaces and assigned IP addresses.

Command example:
ip a

Expected output:
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500
inet 192.168.1.10/24 brd 192.168.1.255 scope global dynamic eth0

This command is part of the iproute2 package and provides more comprehensive and flexible network information.

Viewing Open Ports with netstat -tulnp

The netstat command lists active connections, listening ports, and network statistics. The -tulnp options display TCP and UDP sockets along with the process ID and name.

Command example:
netstat -tulnp

Expected output:
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 758/sshd

This output helps identify services running on specific ports and can be used to detect unwanted network activity.

Monitoring Network Sockets with ss -tuln

The ss command is a faster and more modern replacement for netstat. It shows socket statistics and listening ports.

Command example:
ss -tuln

Expected output:
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:*

It is preferred for performance and accuracy when analyzing network connections.

Tracing Network Routes with traceroute

The traceroute command traces the path that a packet takes to reach a destination. It helps identify where delays or connection issues occur.

Command example:
traceroute example.com

Expected output:
1 192.168.1.1 (192.168.1.1) 2.123 ms
2 10.0.0.1 (10.0.0.1) 4.112 ms
3 203.0.113.1 (203.0.113.1) 10.234 ms

This output shows each hop from the source to the destination IP, including response times for each router along the path.

Performing DNS Lookups with dig

The dig command queries DNS servers to obtain domain name or IP address mappings. It is widely used for troubleshooting DNS issues.

Command example:
dig google.com

Expected output:
;; ANSWER SECTION:
google.com. 299 IN A 142.250.185.78

This output shows the IP address associated with the domain, along with query time and server information.

Querying DNS with nslookup

The nslookup command performs a DNS query for a domain name. It is simple and effective for quick lookups.

Command example:
nslookup example.com

Expected output:
Name: example.com
Address: 93.184.216.34

It is useful for checking DNS resolution, MX records, and name server settings.

Downloading Files with wget

The wget command is used to retrieve files from web servers using HTTP, HTTPS, or FTP protocols. It supports download resumption and recursive downloading.

Command example:
wget

Expected output:
–2025-07-18 10:32:19-
Saving to: ‘file.zip’

This command downloads the file directly to the current working directory.

User and Group Management in Linux

Creating a New User with adduser

The adduser command creates a new user account and sets up the home directory and configuration files.

Command example:
adduser john

Expected output:
Adding user john’ … Creating home directory /home/john’ …
Copying files from `/etc/skel’ …
Enter new UNIX password:

This command walks through the process of setting the password and user information interactively.

Deleting a User with userdel

The userdel command removes a user account. It does not delete the home directory by default unless the -r option is specified.

Command example:
userdel john

This command deletes the user john from the system. Use userdel -r john to also remove their home directory and mail spool.

Changing User Password with passwd

The passwd command changes the password of a user. Only root or the user themselves can execute this command.

Command example:
passwd john

Expected output:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

It is used to reset passwords for users or to force a password change.

Creating a New Group with groupadd

The groupadd command creates a new group on the system. Groups are used to manage permissions for sets of users.

Command example:
groupadd devs

This creates a new group named devs. Users can be added to the group to grant shared access to files or resources.

Modifying a User with usermod

The usermod command is used to change user account properties. A common usage is adding a user to a group.

Command example:
usermod -aG sudo john

This adds john to the sudo group, allowing elevated administrative privileges. The -aG flag ensures the user is added without removing them from other groups.

Viewing User Information with id

The id command displays the user ID and group ID of a specified user. It is useful for verifying permissions and group memberships.

Command example:
id john

Expected output:
uid=1001(john) gid=1001(john) groups=1001(john),27(sudo)

This shows the numeric and named user and group IDs, along with any secondary groups.

Final Thoughts 

Mastering Linux commands is not just about memorizing syntax. It is about understanding how the system works at a foundational level, so you can navigate, manage, and control your environment with precision and efficiency. Whether you are an aspiring system administrator, a cybersecurity analyst, a network engineer, or a developer, fluency with the Linux command line can significantly enhance your productivity, troubleshooting capabilities, and technical confidence.

Throughout this guide, you have explored a wide range of essential Linux commands categorized across four core areas: file and directory management, system information and monitoring, package management, and networking and user control. These commands represent the building blocks of working effectively in any Linux-based system, from a personal development environment to an enterprise-scale server infrastructure.

As you continue your Linux journey, remember that the command line is both a tool and a skill. Real proficiency comes through practice and repetition. Try out these commands in a safe environment such as a virtual machine or a cloud instance. Break things on purpose, fix them, read man pages, explore different options, and experiment with combining commands using pipes and redirection.

Also, be mindful of permissions and the implications of powerful commands like rm, especially with recursive and force flags. The flexibility Linux offers is unmatched, but it also comes with responsibility. A single command can drastically affect system behavior, so it’s crucial to double-check syntax and understand each command’s purpose before executing it.

Lastly, the Linux ecosystem is constantly evolving. New tools emerge, and older ones get replaced or deprecated. Staying current with modern alternatives like the ip and ss commands, understanding package changes in your distribution, and exploring newer text editors and scripting techniques will ensure that your skills remain sharp and relevant.

By internalizing and regularly using these top Linux commands, you are laying the groundwork for deeper technical expertise and unlocking the full potential of one of the most powerful operating systems in the world. Keep learning, stay curious, and make the command line your ally in building, securing, and managing everything from personal projects to enterprise systems.