Linux Command Reference

This reference provides an overview of essential Linux commands for file management, process control, networking, system information, and more. It serves as a quick guide for both beginners and experienced users.

File and Directory Commands

Command Description
ls List files and directories.
cd <directory> Change the current directory.
pwd Print the current working directory.
mkdir <directory> Create a new directory.
rmdir <directory> Remove an empty directory.
rm <file> Delete a file.
rm -r <directory> Recursively delete a directory and its contents.
cp <source> <destination> Copy files or directories.
mv <source> <destination> Move or rename files or directories.
touch <file> Create an empty file or update the timestamp.
cat <file> Display the contents of a file.
less <file> View the contents of a file one page at a time.
head <file> Display the first lines of a file.
tail <file> Display the last lines of a file.
find <path> -name <pattern> Search for files and directories by name.
grep <pattern> <file> Search for patterns within files.

File Permissions and Ownership

Command Description
chmod <permissions> <file> Change the permissions of a file or directory.
chown <owner> <file> Change the owner of a file or directory.
chgrp <group> <file> Change the group ownership.
umask <mask> Set default file creation permissions.

Process Management

Command Description
ps Display information about running processes.
top Display real-time system statistics.
htop An enhanced version of top (may require installation).
kill <PID> Terminate a process by its PID.
killall <process_name> Terminate all processes with the given name.
bg Resume a suspended job in the background.
fg Bring a background job to the foreground.
jobs List current jobs.
nice -n <priority> <command> Start a process with a given priority.
renice <priority> -p <PID> Change the priority of an existing process.

Networking Commands

Command Description
ifconfig or ip addr Display network interface information.
ping <host> Send ICMP ECHO_REQUEST packets to network hosts.
traceroute <host> Trace the route packets take to a network host.
netstat -tuln List open ports and listening services.
nslookup <domain> Query Internet name servers interactively.
dig <domain> DNS lookup utility.
ssh user@host Connect to a remote host securely.
scp <source> <destination> Securely copy files between hosts.
curl <url> Transfer data from or to a server.
wget <url> Retrieve files from the web.

System Information

Command Description
uname -a Display system information.
df -h Show disk space usage.
du -sh <directory> Estimate file space usage.
free -h Display memory usage.
uptime Show how long the system has been running.
who Show who is logged on.
last Show last logged in users.
history Show command history.
man <command> Display the manual page for a command.
info <command> Display info documentation.

Package Management

Debian/Ubuntu-based Systems (using apt):

Command Description
sudo apt update Update package index.
sudo apt upgrade Upgrade installed packages.
sudo apt install <package> Install a package.
sudo apt remove <package> Remove a package.
sudo apt search <package> Search for a package.

Red Hat/CentOS-based Systems (using yum or dnf):

Command Description
sudo yum update Update packages.
sudo yum install <package> Install a package.
sudo yum remove <package> Remove a package.
sudo yum search <package> Search for a package.

Compression and Archiving

Command Description
tar -cvf archive.tar <files> Create a tar archive.
tar -xvf archive.tar Extract a tar archive.
tar -zcvf archive.tar.gz <files> Create a compressed tar archive with gzip.
tar -zxvf archive.tar.gz Extract a gzip compressed tar archive.
zip archive.zip <files> Create a zip archive.
unzip archive.zip Extract a zip archive.
gzip <file> Compress a file with gzip.
gunzip <file.gz> Decompress a gzip file.

User and Group Management

Command Description
sudo adduser <username> Add a new user.
sudo passwd <username> Change a user's password.
sudo deluser <username> Delete a user.
sudo addgroup <groupname> Add a new group.
sudo delgroup <groupname> Delete a group.
sudo usermod -aG <group> <username> Add a user to a group.
id <username> Display user identity.

Disk Management

Command Description
fdisk -l List disk partitions.
mount <device> <mount_point> Mount a filesystem.
umount <mount_point> Unmount a filesystem.
df -h Report filesystem disk space usage.
du -sh <directory> Estimate file space usage.
fsck <device> Check and repair a filesystem.

System Control and Shutdown

Command Description
sudo shutdown -h now Shutdown the system immediately.
sudo shutdown -r now Reboot the system immediately.
sudo reboot Reboot the system.
sudo systemctl start <service> Start a system service.
sudo systemctl stop <service> Stop a system service.
sudo systemctl restart <service> Restart a system service.
sudo systemctl enable <service> Enable a service to start on boot.
sudo systemctl disable <service> Disable a service from starting on boot.
sudo systemctl status <service> Check the status of a service.

Environment Variables and Shell

Command Description
echo $VARIABLE Display the value of an environment variable.
export VARIABLE=value Set or modify an environment variable.
alias <name>='<command>' Create a shell alias.
unalias <name> Remove a shell alias.
env Display all environment variables.

Text Processing

Command Description
grep <pattern> <file> Search for a pattern in files.
sed 's/old/new/g' <file> Replace text in a file using stream editor.
awk '/pattern/ {action}' <file> Pattern scanning and processing language.
sort <file> Sort lines of text files.
uniq <file> Report or filter out repeated lines.
diff <file1> <file2> Compare files line by line.
wc <file> Print newline, word, and byte counts.
tee <file> Read from standard input and write to standard output and files.

Redirection and Pipes

Use redirection and pipes to control input and output:

Examples

# Redirect output to a file
ls -l > filelist.txt

# Append output to a file
echo "New line" >> file.txt

# Redirect error messages to a file
command 2> error.log

# Pipe output to another command
ps aux | grep apache

# Suppress output
command > /dev/null 2>&1

Return to Home