Linux Commands Cheat Sheet

Linux Commands Cheat Sheet

Aung Kyaw Nyunt
Here’s a quick reference guide to essential Linux commands.
It covers common file operations, system administration tasks, user management, network commands, and more.
1. File and Directory Operations
ls – List files and directories.
ls # List files in the current directory ls -l # List files with details (permissions, size, etc.) ls -a # List all files, including hidden ones ls -lh # List files with human-readable sizes (e.g., KB, MB)
cd – Change directory.
cd /path/to/directory # Change to specified directory cd ~ # Change to home directory cd .. # Go up one directory level
pwd – Print working directory.
pwd # Show the current directory path
mkdir – Create a directory.
mkdir newdir # Create a directory named 'newdir' mkdir -p /path/to/dir # Create intermediate directories as needed
rmdir – Remove an empty directory.
rmdir mydir # Remove the empty directory 'mydir'
rm – Remove files or directories.
rm file.txt # Delete a file rm -r mydir # Delete a directory and its contents rm -rf mydir # Forcefully delete a directory (ignores warnings)
cp – Copy files and directories.
cp file1.txt file2.txt # Copy file1.txt to file2.txt cp -r dir1/ dir2/ # Copy a directory and its contents
mv – Move or rename files and directories.
mv file1.txt file2.txt # Rename file1.txt to file2.txt mv file.txt /path/to/dir/ # Move file.txt to another directory
find – Search for files and directories.
find /path -name "filename" # Find files by name find /path -type f -name "*.txt" # Find all .txt files
locate – Find files by name (faster than find if database is up-to-date).
locate filename # Locate a file by name updatedb # Update the database for `locate` (needs root)
touch – Create an empty file or update file timestamps.
touch file.txt # Create an empty file or update file timestamp
2. File Permissions
chmod – Change file permissions.
chmod 755 file.txt # Set rwx for owner, rx for group and others chmod +x file.sh # Make a file executable chmod -r 644 file.txt # Set permissions recursively
chown – Change file ownership.
chown user:group file.txt # Change ownership to user and group chown -R user:group /path # Recursively change ownership
chgrp – Change group ownership.
chgrp group file.txt # Change group ownership of a file
3. Process Management
ps – Show current processes.
ps # Show current processes for the user ps aux # Show all processes (user and system-wide) ps -ef # Show detailed process information (full format)
top – Show system resource usage and process list (interactive).
top # Start top command to show system resource usage
htop – Enhanced version of top (requires installation).
htop # Interactive process viewer with better UI
kill – Kill a process by PID.
kill PID # Terminate a process by its PID kill -9 PID # Forcefully kill a process (SIGKILL)
killall – Kill processes by name.
killall process_name # Kill all processes by name
bg – Resume a job in the background.
bg %1 # Resume job 1 in the background
fg – Bring a job to the foreground.
fg %1 # Bring job 1 to the foreground
4. Disk Usage
df – Show disk space usage.
df # Display free disk space for mounted filesystems df -h # Human-readable format (GB, MB)
du – Show disk usage of files and directories.
du -sh /path/to/dir # Show total size of directory du -ah /path/to/dir # Show size of all files and directories
mount – Mount a filesystem or view mounted filesystems.
mount # Show all mounted filesystems mount /dev/sdX /mnt # Mount a filesystem to a directory
umount – Unmount a filesystem.
umount /mnt # Unmount the filesystem mounted at /mnt
5. Network Commands
ping – Check network connectivity.
ping google.com # Ping a remote host ping -c 4 google.com # Ping 4 times and stop
ifconfig – Show network interface configuration (deprecated, use ip).
ifconfig # Show all network interfaces and their details
ip – Show or configure network interfaces (modern alternative to ifconfig).
ip a # Show all network interfaces ip addr show # Show detailed network interface information
netstat – Network statistics and connections.
netstat -tuln # Show listening ports and active connections
ss – Utility to investigate sockets (modern replacement for netstat).
ss -tuln # Show listening ports and active connections
scp – Securely copy files between hosts.
scp file.txt user@remote:/path/to/destination # Copy file to remote server scp user@remote:/path/to/file.txt /local/path # Copy file from remote server
ssh – Securely connect to a remote server.
ssh user@remote_host # SSH into a remote host
wget – Download files from the web.
wget http://example.com/file.zip # Download a file
curl – Transfer data from or to a server.
curl -O http://example.com/file.zip # Download a file with curl
6. File Compression and Archiving
tar – Archive files.
tar -cvf archive.tar file1 file2 # Create a tar archive tar -xvf archive.tar # Extract a tar archive tar -cvzf archive.tar.gz files # Create a gzipped tar archive tar -xvzf archive.tar.gz # Extract a gzipped tar archive
gzip – Compress files using gzip.
gzip file.txt # Compress file.txt into file.txt.gz gunzip file.txt.gz # Decompress file.txt.gz
zip – Create a ZIP archive.
zip archive.zip file1 file2 # Create a zip archive unzip archive.zip # Extract a zip archive
7. System Information
uname – Show system information.
uname -a # Show all system information (kernel, OS, etc.) uname -r # Show kernel version
uptime – Show how long the system has been running.
uptime # Show system uptime
dmesg – Show kernel ring buffer messages (system startup logs).
dmesg # Show the kernel ring buffer messages
free – Show memory usage.
free -h # Show memory usage in human-readable format
top – View system resource usage (CPU, memory, processes).
top # Interactive process viewer
vmstat – Report system performance (memory, processes, CPU).
vmstat # Show system performance statistics
8. User Management
whoami – Show current logged-in user.
whoami # Show the current logged-in user
adduser – Add a new user.
sudo adduser username # Create a new user
passwd – Change user password.
sudo passwd username # Change password for a user
userdel – Delete a user.
sudo userdel username # Delete a user
groupadd – Add a new group.
sudo groupadd groupname # Create a new group
groups – Show the groups a user belongs to.
groups username # Show groups for a user
9. Searching Files and Content
grep – Search for text in files.
grep "search_term" file.txt # Search for 'search_term' in file.txt grep -r "search_term" /dir # Search recursively in a directory
which – Show the path of an executable.
which python # Show path of the python executable
find – Search for files and directories.
find /path -name "filename" # Find files by name find /path -type f -name "*.txt" # Find .txt files
This cheat sheet covers many of the most frequently used commands in Linux, but there’s always more to explore!
Let me know if you need help with any specific command or additional topics. aungkyawnyut2004@gmail.com
Happy Codding ;)
https://www.applix.info
© All right Reserved. Inspired Codes...
Get In Touch
Rule and Policy