Overview
Linux basic commands

Linux basic commands

September 18, 2025
10 min read
index

Unlock the full potential of your Linux system with this comprehensive guide to essential Linux commands. Whether you’re a seasoned administrator or just starting out, mastering these commands is crucial for efficient server management, script writing, and troublesshooting. In this tutorial, you will learn the most frequently used and powerful commands for file management, process control, user access, network configuration, and system debugging.

Introduction

Unlock the full potential of your Linux system with this comprehensive guide to essential Linux commands. Whether you’re a seasoned administrator or just starting out, mastering these commands is crucial for efficient server management, script writing, and troubleshooting.

You will learn over must-know Linux commands that will transform you into a Linux power user. From basic to advanced, these commands will become your go-to tools for tackling any task that comes your way.

Answer

Ever heard a developer say, “I just need a little bit of sudo privilege!”? The Linux Terminal is where those stories begin. Get ready to be the master of the black box, where everything is just a few keystrokes away!

Sudo meme ubuntu

Prerequisites

We will be running these commands on a Ubuntu server, but you can follow along on any modern Linux distribution. You can set up a Ubuntu server for this tutorial by following our guide to Initial Server Setup on Ubuntu

File and Directory Commands

CommandDescriptionExample
lsList directory contents.ls
cdChange directorycd /path/to/directory
pwdShow current directorypwd
mkdirCreate a new directorymkdir new_directory
rmdirRemove and empty directoryrmdir empty_directory
rmDelete files or directoriesrm file.go
touchCreate an empty filetouch new_file
cpCopy files or directories.cp file.txt /path/to/destination
mvMove or rename filesmv file.txt /path/to/new_location
catDisplay file contents.cat file.txt
nano / vimEdit files in terminal.nano file.txt
findSearch for files in a directory hierarchy.find . -name "file.txt"
grepSearch text using patternsgrep "pattern" file.txt
tarArchive and compress files.tar -cvf archive.tar file1.txt file2.txt
dfShow disk usage of file systems.df
duShow directory/file size.du -sh /path/to/directory
chmodChange file permissionschmod 755 file.txt
chownChange file ownerchown user:group file.txt
mountMount a filesystemmount /dev/sdb1 /mnt
umountUnmount a filesystemumount /mnt
Warning

You’ve seen the power of rm. It deletes files, directories, and if you use the wrong flags, it can delete… your entire afternoon. Be extremely careful with rm -rf /—it’s not just a command, it’s the IT world’s “Delete System 32” button. Don’t press it!

Sudo meme ubuntu

Networking Commands

CommandDescriptionExample usage
pingTest connectivity to a host.ping google.com
ifconfig / ip aDisplay network interfaces.ifconfig or ip a
netstat / ssShow network connections.netstat -tuln or ss -tuln
wgetDownload files via HTTP/FTP.wget http://example.com/file.zip
curlTransfer 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
tcpdumpCapture and analyze network packets.tcpdump -i eth0
iptablesConfigure firewall rules.iptables -A INPUT -p tcp --dport 22 -j ACCEPT
tracerouteTrace the path packets take to a network host.traceroute example.com
nslookupQuery DNS to obtain domain name or IP address mapping.nslookup example.com
sshSecurely connect to a remote host.ssh user@example.com

Process and system monitoring commands

CommandDescriptionExample command
psShow running processes.ps aux
topDynamic process viewer.top
htopEnhanced version of tophtop
killSend a signal to a processkill <PID>
killallKill processes by namekillall <process_name>
uptimeSystem uptime and load.uptime
whoamiCurrent logged-in user.whoami
envDisplay environment variablesenv
straceTrace system calls of a process.strace -p <PID>
systemctlManage systemd servicessystemctl status <service_name>
journalctlView system logs.journalctl -xe
freeDisplay memory usage.free -h
vmstatReport virtual memory statistics.vmstat 1
iostatReport CPU and I/O statisticsiostat
lsofList open files by processeslsof
dmesgPrint kernel ring buffer messages.dmesg

Joke: What’s the fastest way to solve an unidentified performance issue? Run top, find a strange process you don’t recognize, and then kill -9 it. Then, immediately start praying it wasn’t critical.

User and Permission Management Commands

CommandDescriptionExample command
passwdChange user password.passwd <username>
adduser / useraddAdd a new useradduser <username> or useradd <username>
deluser / userdelDelete a user.deluser <username> or userdel <username>
usermodModify user account.usermod -aG <group> <username>
groupsShow group memberships.groups <username>
sudoExecute commands as root.sudo <command>
chageChange user password expiry information.chage -l <username>
idDisplay user identity information.id <username>
newgrpLog in to a new group.newgrp <group>

File transfer and synchronization commands

CommandDescriptionExample command
scpSecurely copy files over SSH..scp user@remote:/path/to/file /local/destination
rsyncEfficiently sync files and directories.rsync -avz /local/directory/ user@remote:/path/to/destination
ftpTransfer files using the File Transfer Protocol.ftp ftp.example.com
sftpSecurely transfer files using SSH File Transfer Protocol.sftp user@remote:/path/to/file
wgetDownload files from the web.wget http://example.com/file.zip
curlTransfer data from or to a server.curl -O http://example.com/file.zip
chageChange user password expiry information.chage -l <username>
idDisplay user identity information.id <username>
newgrpLog in to a new group.newgrp <group>

Text processing commands

CommandDescriptionExample command
awkPattern scanning and processing.awk '{print $1}' file.txt
sedStream editor for filtering/modifying text.sed 's/old/new/g' file.txt
cutRemove sections from lines of text.cut -d':' -f1 /etc/passwd
sortSort lines of text.sort file.txt
grepSearch for patterns in text.grep 'pattern' file.txt
wcCount words, lines, and characters.wc -l file.txt
pasteJoin lines of two files on a common field.join file1.txt file2.txt
headOutput the first part of files.head -n 10 file.txt
tailOutput the last part of files.tail -n 10 file.txt

Shell Utilities and Shortcuts Commands

CommandDescriptionExample command
aliasCreate shortcuts for commands.alias ll='ls -la'
unaliasRemove an alias.sunalias ll
historyShow previously entered commands.history
clearClear the terminal screen.clear
rebootReboot the system.reboot
shutdownPower off the system.shutdown now
dateDisplay or set the system date and time.date
echoDisplay a line of text.echo "Hello, World!"
sleepDelay for a specified amount of time.sleep 5
timeMeasure the duration of command execution.time ls
watchExecute a program periodically, showing output fullscreen.watch -n 5 df -h

Now let’s dive a little deeper into each of these commands and understand them in more detail. We already have a lot of existing articles for each of those individual commands. For your convenience, we’ll add links to all the existing articles, and continue to update the article as new topics are covered.

As you can see in the above image, using the command by itself without any arguments will give us an output with all the files and directories in the directory. The command offers a lot of flexibility in terms of displaying the data in the output.

Common Errors and Debugging

When working with Linux commands, you may encounter various errors and issues. Here are some common problems and how to resolve them:

1. Fixing “command not found” errors

If you receive a command not found error, it means that the command you are trying to run is not recognized by the system. This can happen for several reasons:

  1. The command is not installed on your system. You can install it using your package manager (e.g., apt, yum, dnf). If you see:
    Terminal window
    bash: xyz: command not found
    Use:
    Terminal window
    which xyz
    If the command isn’t installed, try installing:
    Terminal window
    apt-get install <package-name>
  2. The command is not in your system’s PATH. You can add the directory containing the command to your PATH.
    Terminal window
    export PATH=$PATH:/path/to/command
  3. You made a typo. Double-check the command for any spelling errors.
Command not found

A confused person looking intensely at a monitor with the command not found message

2. Resolving permission issues with sudo

If you encounter permission issues, you can use sudo to run the command with superuser privileges.

Terminal window
sudo command_name

3. Handling File Conflicts

File conflicts can occur when multiple users or processes attempt to modify the same file simultaneously. Here are some ways to handle file conflicts:

  1. Use Version Control Systems (VCS): Tools like Git can help manage file conflicts by allowing users to merge changes and resolve conflicts manually.
Terminal window
git merge <branch_name>

If there are conflicts, Git will prompt you to resolve them. Open the conflicting files, make the necessary changes, and then commit the resolved files.

Terminal window
git add <resolved_file>
git commit -m "Resolved merge conflict"
  1. Locking Mechanisms: Implement file locking to prevent multiple processes from writing to the same file simultaneously. Use flock in Linux to create a lock on a file.
Terminal window
flock -x <file> -c "<command>"
  1. Atomic Operations: Use atomic operations to ensure that file writes are completed in a single step, reducing the risk of conflicts.
Terminal window
mv temp_file target_file

Or, Use mv with -f (force) or cp with -i (interactive):

Terminal window
mv -f file1 file2
cp -i file1 file2

4. Debugging Performance Bottlenecks

  1. Identify the Bottleneck: Use tools like top, htop, vmstat, and iostat to monitor system performance and identify the resource causing the bottleneck (CPU, memory, disk I/O, etc.).
Terminal window
top
  1. Analyze Logs: Check system and application logs for any errors or warnings that might indicate performance issues.
Terminal window
tail -f /var/log/syslog
  1. Optimize code: Review and optimize your code to improve performance. Look for inefficient algorithms, unnecessary computations, and memory leaks.
  2. Profile your application: Use profiling tools like gprof, perf, or valgrind to analyze your application’s performance and identify slow functions or memory issues.
Terminal window
gprof <executable> gmon.out
  1. Scale resources: If the bottleneck is due to resource limitations, consider scaling up your hardware or using load balancing to distribute the load across multiple servers.

Conclusion

I hope you found this article helpful in understanding various Linux commands and their usage. Mastering these basics is the key to truly owning your environment. Now go forth and conquer the terminal!