A comprehensive list of Linux commands, from basic to advanced.
Basic Commands
pwd: Print Working Directory
Description: Displays the full path to the current directory.
Example:
pwd
cd [directory]: Change Directory
Description: Changes the current directory to the specified directory.
Example:
cd /path/to/directory
cd ~ # Change to home directory
cd .. # Move up one directory
ls [options] [directory]: List Directory Contents
Description: Lists files and directories within the specified directory.
Example:
ls # List files in current directory
ls -l # List files with detailed information
ls -a # List all files including hidden files
ls -lh # List files with human-readable file sizes
touch [filename]: Create an empty file or update the timestamp
Description: Creates a new empty file or updates the access and modification times of an existing file.
Example:
touch newfile.txt
cp [source] [destination]: Copy files or directories
Description: Copies files or directories from the source to the destination.
Example:
cp file1.txt /path/to/destination/
cp -r /path/to/source /path/to/destination/ # Copy directories
mv [source] [destination]: Move or rename files or directories
Description: Moves or renames files or directories.
Example:
mv oldname.txt newname.txt
mv /path/to/source /path/to/destination/
rm [file]: Remove files
Description: Deletes files or directories.
Example:
rm file1.txt
rm -r /path/to/directory/ # Remove directories
mkdir [directory]: Create a new directory
Description: Creates a new directory.
Example:
mkdir new_directory
rmdir [directory]: Remove an empty directory
Description: Removes an empty directory.
Example:
rmdir empty_directory
Viewing and Editing Files
cat [file]: Concatenate and display file content
Description: Displays the content of a file.
Example:
cat file1.txt
more [file]: View file content one screen at a time
Description: Views the content of a file one screen at a time.
Example:
more file1.txt
less [file]: View file content with backward navigation
Description: Views the content of a file with the ability to scroll both forward and backward.
Example:
less file1.txt
nano [file]: Edit files using the Nano text editor
Description: Edits files using the Nano text editor.
Example:
nano file1.txt
vi [file]: Edit files using the Vi text editor
Description: Edits files using the Vi text editor.
Example:
vi file1.txt
File Permissions and Ownership
chmod [permissions] [file]: Change file permissions
Description: Changes the permissions of a file or directory.
Example:
chmod 755 script.sh # Owner: read/write/execute; Group: read/execute; Others: read/execute
chown [owner]:[group] [file]: Change file owner and group
Description: Changes the owner and group of a file or directory.
Example:
chown user:group file1.txt
Searching and Finding Files
find [directory] [options] [expression]: Search for files in a directory hierarchy
Description: Searches for files and directories within a specified directory hierarchy based on given criteria.
Example:
find /path/to/search -name “*.txt”
grep [options] [pattern] [file]: Search text using patterns
Description: Searches for patterns within files.
Example:
grep “search_term” file1.txt
grep -r “search_term” /path/to/search # Recursive search in directories
System Information
df [options]: Report file system disk space usage
Description: Displays the amount of disk space used and available on file systems.
Example:
df -h # Human-readable format
du [options] [directory]: Estimate file space usage
Description: Displays the disk space used by files and directories.
Example:
du -sh /path/to/directory # Summarize total size
top: Display Linux tasks
Description: Displays real-time system information including tasks, CPU, and memory usage.
Example:
top
htop: Interactive process viewer (requires installation)
Description: Provides an interactive process viewer for monitoring system processes.
Example:
htop
uname [options]: Print system information
Description: Displays system information such as the kernel version.
Example:
uname -a # All information
uname -r # Kernel version
uptime: Show how long the system has been running
Description: Displays the system uptime, load averages, and the number of users logged in.
Example:
uptime
who: Show who is logged on
Description: Displays information about users currently logged into the system.
Example:
who
date: Display or set the system date and time
Description: Displays or sets the system date and time.
Example:
date
Networking
ping [host]: Send ICMP ECHO_REQUEST to network hosts
Description: Sends packets to a network host to check connectivity and measure round-trip time.
Example:
ping google.com
ifconfig [interface]: Configure a network interface
Description: Configures or displays network interface parameters.
Example:
ifconfig
netstat [options]: Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships
Description: Displays network connections, routing tables, and interface statistics.
Example:
netstat -tuln # Show listening ports
traceroute [host]: Print the route packets take to the network host
Description: Displays the route packets take to reach a network host.
Example:
traceroute google.com
wget [url]: Non-interactive network downloader
Description: Downloads files from the web non-interactively.
Example:
wget http://example.com/file.zip
curl [options] [url]: Transfer data from or to a server
Description: Transfers data from or to a server using various protocols.
Example:
curl http://example.com
curl -O http://example.com/file.zip # Download a file
Package Management (Debian/Ubuntu)
apt-get [options] [command]: APT package handling utility
Description: Manages packages in Debian-based distributions.
Example:
sudo apt-get update # Update package lists
sudo apt-get upgrade # Upgrade all packages
sudo apt-get install package_name # Install a package
sudo apt-get remove package_name # Remove a package
Sure, here are more advanced and administrative commands:
Package Management (RHEL/CentOS)
yum [options] [command]: Package manager utility
Description: Manages packages in RHEL (Red Hat Enterprise Linux) and CentOS.
Example:
“`
bash
sudo yum update # Update package lists
sudo yum install package_name # Install a package
sudo yum remove package_name # Remove a package
dnf [options] [command]: Package manager utility (replaces yum in newer versions)
Description: Manages packages in newer versions of RHEL and CentOS.
Example:
“`
bash
sudo dnf update # Update package lists
sudo dnf install package_name # Install a package
sudo dnf remove package_name # Remove a package
Process Management
ps [options]: Report a snapshot of current processes
Description: Displays information about active processes.
Example:
“`
bash
ps aux # All processes with user-oriented format
kill [pid]: Terminate a process by PID
Description: Terminates a process with the specified process ID.
Example:
“`
bash
kill 1234 # Kill process with PID 1234
kill -9 1234 # Force kill process with PID 1234
pkill [pattern]: Send signals to processes based on name and other attributes
Description: Terminates processes based on name or other attributes.
Example:
“`
bash
pkill -f process_name # Kill all processes matching name
pgrep [options] [pattern]: List processes based on name and other attributes
Description: Lists processes based on name or other attributes.
Example:
“`
bash
pgrep -l -u username # List processes owned by a specific user
Disk Management
mount [options] [device] [directory]: Mount a file system
Description: Mounts a file system to the specified directory.
Example:
“`
bash
mount /dev/sda1 /mnt
umount [device]: Unmount a file system
Description: Unmounts a mounted file system.
Example:
“`
bash
umount /mnt
fdisk [options] [device]: Partition table manipulator for Linux
Description: Manages disk partitions.
Example:
“`
bash
sudo fdisk -l # List partitions
sudo fdisk /dev/sdb # Interactively manage partitions of /dev/sdb
df [options]: Report file system disk space usage
Description: Displays disk space usage of file systems.
Example:
“`
bash
df -h # Human-readable format
Compression and Archiving
tar [options] [archive] [file/directory]: Archive files
Description: Creates an archive file from files and directories.
Example:
“`
bash
tar -cvf archive.tar file1 file2 # Create archive
tar -xvf archive.tar # Extract archive
tar -czvf archive.tar.gz file1 file2 # Create compressed archive
tar -xzvf archive.tar.gz # Extract compressed archive
gzip [file]: Compress files
Description: Compresses a file using gzip compression.
Example:
“`
bash
gzip file1
gunzip [file]: Decompress files
Description: Decompresses a file compressed with gzip.
Example:
“`
bash
gunzip file1.gz
User Management
useradd [options] username: Add a new user
Description: Adds a new user to the system.
Example:
“`
bash
sudo useradd newuser
usermod [options] username: Modify a user account
Description: Modifies user account attributes.
Example:
“`
bash
sudo usermod -aG groupname username # Add user to group
passwd [username]: Change user password
Description: Changes the password for a user.
Example:
“`
bash
sudo passwd username
userdel [options] username: Delete a user account
Description: Deletes a user account from the system.
Example:
“`
bash
sudo userdel username
Miscellaneous
shutdown [options]: Shutdown or restart the system
Description: Shuts down or restarts the system.
Example:
“`
bash
sudo shutdown -h now # Shutdown immediately
sudo shutdown -r now # Restart immediately
cron [options]: Schedule commands to run at a specified time
Description: Schedules commands to run at a specified time.
Example:
“`
bash
crontab -e # Edit crontab file to schedule tasks
at [options] time: Schedule commands to run once at a specified time
Description: Schedules commands to run once at a specified time.
Example:
“`
bash
at now + 1 hour
These commands cover a wide range of tasks from basic file management to system administration and advanced networking.