Linux Cheatsheet

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

being._.developer__ being.

developer
Basic Commands
1. Navigation
pwd - Print working directory
ls - List directory contents
cd [directory] - Change directory
cd .. - Move to parent directory

2. File Operations
touch [file] - Create a new file
cat [file] - Display file content
cp [source] [destination] - Copy files or directories
mv [source] [destination] - Move or rename files or directories
rm [file] - Remove a file
rm -r [directory] - Remove a directory and its contents

3. Directory Operations
mkdir [directory] - Create a new directory
rmdir [directory] - Remove an empty directory

Intermediate Commands
1. Permissions
chmod [permissions] [file] - Change file permissions
chown [owner]:[group] [file] - Change file owner and group

2. Viewing and Editing Files


nano [file] - Open file in nano editor
vi [file] - Open file in vi editor
grep [pattern] [file] - Search for a pattern in a file
head [file] - Display the first 10 lines of a file
tail [file] - Display the last 10 lines of a file
tail -f [file] - Continuously display new lines added to a file
3. Networking
ping [host] - Send ICMP ECHO_REQUEST to network hosts
ifconfig - Display or configure a network interface
netstat - Print network connections, routing tables, interface statistics,
masquerade connections, and multicast memberships
curl [url] - Transfer data from or to a server
wget [url] - Download files from the web

4. System Monitoring
top - Display tasks and system resource usage
htop - Interactive process viewer
ps aux - Show all running processes
df -h - Display disk space usage in human-readable format
du -h [directory] - Display directory size in human-readable format

Advanced Commands
1. Package Management (Debian-based)
apt-get update - Update package list
apt-get upgrade - Upgrade installed packages
apt-get install [package] - Install a package
apt-get remove [package] - Remove a package

2. Package Management (Red Hat-based)


yum update - Update package list and upgrade installed packages
yum install [package] - Install a package
yum remove [package] - Remove a package

3. User Management
adduser [username] - Add a new user
passwd [username] - Change a user's password
usermod -aG [group] [username] - Add a user to a group
deluser [username] - Delete a user
4. Disk Management
fdisk -l - List disk partitions
mkfs.ext4 [device] - Create an ext4 filesystem
mount [device] [directory] - Mount a filesystem
umount [directory] - Unmount a filesystem

5. System Control
systemctl status [service] - Check the status of a service
systemctl start [service] - Start a service
systemctl stop [service] - Stop a service
systemctl restart [service] - Restart a service
systemctl enable [service] - Enable a service to start at boot
systemctl disable [service] - Disable a service from starting at boot

6. Advanced Networking
ip a - Show network interfaces and IP addresses
iptables -L - List firewall rules
ssh [user]@[host] - Connect to a remote host via SSH
scp [file] [user]@[host]:[destination] - Secure copy files between hosts

7. Process Management
kill [PID] - Terminate a process by PID
killall [process_name] - Terminate all processes with a given name
nohup [command] & - Run a command immune to hangups, with output to a non-
tty

8. Archive and Compression


tar -cvf [archive.tar] [file/directory] - Create a tarball
tar -xvf [archive.tar] - Extract a tarball
gzip [file] - Compress a file
gunzip [file.gz] - Decompress a file
Additional Commands
1. File Viewing and Manipulation
less [file] - View file content one screen at a time
sort [file] - Sort the contents of a file
uniq [file] - Report or filter out repeated lines in a file
diff [file1] [file2] - Compare two files line by line

2. Disk Usage and Quota


lsblk - List information about block devices
blkid - Locate/print block device attributes
quota -u [username] - Display user disk usage and limits

3. Scheduled Tasks
crontab -e - Edit user crontab
crontab -l - List user crontab entries
at [time] - Schedule a command to be run at a specified time

4. System Information
uname -a - Print all system information
hostnamectl - Query and change the system hostname
dmesg - Print or control the kernel ring buffer
lshw - List hardware configuration

5. Text Processing
awk '{print $1}' [file] - Extract the first column of a file
sed 's/old/new/g' [file] - Replace all occurrences of 'old' with 'new' in a
file
cut -d ' ' -f1 [file] - Cut out the first field of a file

6. Advanced Networking
traceroute [host] - Print the route packets take to the network host
nc -zv [host] [port] - Check the open port on a remote host
ss -tuln - List open sockets

7. Advanced File System Operations


mount -o loop [iso] [directory] - Mount an ISO file
umask [mask] - Set file creation mask
fsck [device] - Check and repair a filesystem

8. Security
gpg -c [file] - Encrypt a file
gpg [file.gpg] - Decrypt a file
ssh-keygen -t rsa - Generate an RSA key pair
chmod 700 [directory] - Set directory permissions to be accessible only by
the owner

9. Backup and Restore


rsync -av [source] [destination] - Synchronize files/directories
dd if=[source] of=[destination] - Copy and convert files
tar -cvpzf [backup.tar.gz] --exclude=[dir] [directory] - Create a
compressed backup excluding certain directories

10. Process Management


bg - Resume a suspended job in the background
fg - Bring a background job to the foreground
jobs - List active jobs

You might also like