Mastering Essential Linux Commands

๐ File & Directory Management
| Command | Description |
| ls | List directory contents. |
| ls -l | Long listing format with permissions, size, and timestamp. |
| ls -a | Show all files, including hidden ones. |
| cd [directory] | Change to the specified directory. |
| cd .. | Go one level up in the directory tree. |
| cd ~ | Navigate to the home directory. |
| pwd | Print the current working directory. |
| mkdir [directory] | Create a new directory. |
| mkdir -p path/to/directory | Create nested directories. |
| rmdir [directory] | Remove an empty directory. |
| rm [file] | Delete a file. |
| rm -r [directory] | Recursively delete a directory and its contents. |
| rm -f [file] | Force delete a file (no prompt). |
| cp [source] [destination] | Copy files or directories. |
| cp -r [source] [destination] | Recursively copy directories. |
| mv [source] [destination] | Move or rename files/directories. |
| touch [file] | Create a new file or update the timestamp. |
| stat [file] | Display detailed information about a file. |
| basename [path] | Get the file name from the path. |
| dirname [path] | Get the directory name from the path. |
๐ File Viewing & Editing
| Command | Description |
| cat [file] | Display file contents. |
| zcat [file.gz] | View the contents of a compressed file. |
| more [file] | View file contents one page at a time. |
| less [file] | Similar to more, but with backward navigation and search support. |
| head [file] | Display the first 10 lines of a file. |
| head -n 5 [file] | Display the first 5 lines of a file. |
| tail [file] | Display the last 10 lines of a file. |
| tail -f [file] | Continuously monitor a file for new lines (commonly used for logs). |
| wc [file] | Show line, word, and character counts for a file. |
| cut -b 1-4 [file] | Display bytes from position 1 to 4 of each line. |
| cut -d ":" -f 1 [file] | Cut fields using a delimiter (e.g., colon). |
| sort [file] | Sort file content alphabetically. |
| uniq [file] | Filter out repeated lines in a sorted file. |
| tee [file] | Display output and write it to a file simultaneously. |
| diff [file1] [file2] | Show the difference between the two files line by line. |
| cmp [file1] [file2] | Compare two files byte by byte. |
| file [file] | Identify the type of a file. |
| nano [file] | Open a file in the Nano text editor. |
| vim [file] / vi [file] | Open a file in the Vim/Vi text editor. |
| :wq | Save and exit in Vim/Vi editor. |
| echo "text" | Display text in the terminal. |
| echo "text" > [file] | Write text to a file (overwrite). |
| echo "text" >> [file] | Append text to a file. |
| ln -s [original_file] [symlink_name] | Create a symbolic (soft) link. Acts like a shortcut and breaks when the original is deleted |
| ln [original_file] [hardlink_name] | Create a hard link. |
| nohup [command] | Run a command immune to hangups, output logged to nohup.out. |
๐ Permissions & Ownership
| Command | Description |
chmod [permissions] [file] | Change file permissions (e.g., chmod 777). |
chown [owner]:[group] [file] | Change the owner and group of a file. |
chgrp [group] [file] | Change group ownership. |
umask | View default permission mask. |
ls -l | View file permissions. |
lsattr | List file attributes. |
chattr +i [file] | Make a file immutable. |
getfacl [file] | Get file access control list. |
setfacl -m u:username:rwx [file] | Set file permissions for a specific user. |
โ๏ธ System Monitoring & Management
| Command | Description |
| fuser . | Show processes using a file/directory. |
| top | Real-time process viewer. |
| htop | Enhanced top (needs installation). |
| ps aux | List all processes. |
| kill [PID] | Terminate the process by ID. |
| kill -9 [PID] | Force kill the process. |
| pkill [name] | Kill the process by name. |
| uptime | Show system uptime and load. |
| df -h | Show disk usage in human-readable format. |
| du -sh [directory] | Show the size of the directory. |
| free -h | Show memory usage. |
| vmstat | Show virtual memory statistics. |
| vmstat -a | Show active/inactive memory. |
| iostat | Display CPU and device I/O stats. |
| who | Show logged-in users. |
| w | Show active users. |
| hostname | Show system hostname. |
| uname -a | Show system/kernel information. |
| dmesg | View kernel ring buffer messages. |
| history | Show command history. |
| watch [command] | Run a command repeatedly every 2 seconds. |
| time [command] | Measure the execution time of a command. |
| strace [command] | Debug command execution (syscalls). |
| lsof | List open files. |
| date | Display current date and time. |
| whoami | Show current user. |
| which [command] | Show command path. |
๐ฅ User & Group Management
| Command | Description |
| sudo [command] | Run command with superuser privileges. |
| sudo su | Switch to root user. |
| useradd -m [user] | Add a new user with home directory. |
| userdel [user] | Delete a user. |
| passwd [user] | Change/set a password. |
| su [user] | Switch to another user. |
| groupadd [group] | Create a new group. |
| groupdel [group] | Delete a group. |
| cat /etc/passwd | View user accounts. |
| cat /etc/group | View groups. |
| sudo gpasswd -a [user] [group] | Add a user to a group. |
| sudo gpasswd -M [u1,u2] [group] | Add multiple users to a group. |
| sudo usermod -aG docker $USER | Adds docker to the group |
๐ฆ Package Management
| Command | Description |
| apt / apt-get | Debian/Ubuntu package manager. |
| sudo apt remove <package_name> | Remove a package. |
| yum | RHEL/CentOS package manager. |
| dnf | Fedora package manager. |
| pacman | Arch Linux package manager. |
| portage | Gentoo package manager. |
| rpm | Install/manage RPM packages. |
๐ฆ Archiving & Compression
| Command | Description |
| zip [file.zip] [file] | Create a zip archive. |
| unzip [file.zip] | Extract zip archive. |
| gzip [file] | Compress file with gzip. |
| gunzip [file.gz] | Decompress gzip file. |
| tar -cvf archive.tar files | Create a tar archive. |
| tar -xvf archive.tar | Extract a tar archive. |
| tar -czvf archive.tar.gz files | Create a tar.gz archive. |
| tar -xzvf archive.tar.gz | Extract tar.gz archive. |
๐ Networking
| Command | Description |
| ping [host] | Test connectivity. |
| netstat | Show network statistics. |
| ifconfig | Show network interfaces. |
| traceroute [host] | Trace route to a host. |
| tracepath [host] | Alternative to traceroute. |
| mtr [host] | Interactive traceroute. |
| nslookup [host] | Query DNS. |
| dig [host] | DNS lookup tool. |
| telnet [host port] | Open telnet connection. |
| ip [options] | IP address management. |
| iwconfig | Wireless config. |
| ss | Socket statistics. |
| arp -a | Show ARP cache. |
| nc [opts] | Netcat (network debugging). |
| whois [domain] | Domain whois info. |
| ifplugstatus | Show network cable status. |
| curl [url] | Transfer data from/to a server. |
| wget [url] | Download files. |
| jq | Parse JSON responses. |
| iptables | Manage firewall rules. |
| nmap [target] | Network scanner. |
| route -n | Show routing table. |
๐ Text Processing
| Command | Description |
| grep [pattern] [file] | Search text in files. |
| grep -i | Case-insensitive search. |
| grep -n | Show line numbers. |
| grep -r | Recursive search. |
| grep -c | Count matching lines. |
| grep -e | Multiple patterns. |
| awk '{print $1}' [file] | Process text fields. |
| sed 's/a/b/g' [file] | Stream editor for replacements. |
๐ File Transfer & Sync
| Command | Description |
| scp [src] [user@host:/dest] | Securely copy files between systems. |
| rsync -avz [src] [dest] | Sync files between local/remote systems. |
๐พ Storage & Volumes
| Command | Description |
| lsblk | List block devices. |
| pvcreate [disk] | Create a physical volume. |
| vgcreate [vg] [pv] | Create a volume group. |
| vgs | Display volume groups. |
| vgdisplay | Show volume group details. |
| pvdisplay | Show physical volume details. |
| lvcreate -L 5G -n lv vg | Create a logical volume. |
| lvs | Show logical volumes. |
| lvdisplay | Show LV details. |
| mkfs.ext4 [lv] | Format as ext4. |
| mkfs -t ext4 [lv] | Alternative format. |
| mount [device] [dir] | Mount a filesystem. |
| umount [dir] | Unmount a filesystem. |
| lvextend -L +2G [lv] | Extend logical volume. |



