1. Basic Linux Commands
| ls | List files in a directory |
| cd | Change directory |
| pwd | Show current directory =path |
| cp | Copy files or directories |
| mv | Move or rename files |
| rm | Remove files or =directories |
| mkdir | Create a new directory |
| rmdir | Remove empty directory |
| touch | Create empty file |
| cat | View contents of a file |
| nano / vim | Text editors in terminal |
| chmod | Change file permissions |
| chown | Change file owner |
| find | Find files by name or type |
| grep | Search text in files |
| df -h | Disk usage summary (human-readable) |
| du -sh | Directory size |
| ps aux | List running processes |
| top / htop | Real-time system monitoring |
| kill | Kill a process by PID |
| man | View manual pages for commands |
| clear | Clear terminal screen |
| exit | Close terminal session |
2. File permissions & ownership
| ls -l | Lists files with permissions, ownership, size, and modification date. |
| chmod [options] mode file | Changes permissions of a file or directory. |
| chmod 755 script.sh | Sets read, write, and execute for owner; read and execute for group and others. |
| chmod u+x file | Adds execute permission to the user (owner). |
| chmod g-w file | Removes write permission from the group. |
| chmod o=r file | Sets read-only for others. |
Group Management
| chgrp group file | Changes the group ownership of a file. |
| groups | Lists groups the current user belongs to. |
| usermod -aG group user | Adds a user to a group (requires root). |
permissions
| read+write+execute(rwx)=7 |
| read+write(rw-)=6 |
| read+execute(r-x)=5 |
| read(r–)=4 |
| write(-w-)=2 |
| execute(–x)=1 |
| no permission(—)=0 |
3. File compression or Archive
a. Creating Archives
| tar -cf archive.tar file1 file2 | Create an uncompressed archive from file1 and file2. |
| tar -cvf archive.tar dir/ | Create archive from a directory with verbose output. |
| tar -czf archive.tar.gz dir/ | Create a gzip-compressed archive. |
| tar -cjf archive.tar.bz2 dir/ | Create a bzip2-compressed archive. |
| tar -caf archive.tar.xz dir/ | Create an archive and compress it with xz. |
| tar -czvf archive.tar.gz * | Archive and compress all files in the current directory. |
b. Extracting Archives
| tar -xf archive.tar | Extract contents of a .tar file. |
| tar -xvf archive.tar | Same as above, with verbose output. |
| tar -xzf archive.tar.gz | Extract a .tar.gz archive. |
| tar -xjf archive.tar.bz2 | Extract a .tar.bz2 archive. |
| tar -xvf archive.tar -C /target/dir/ | Extract to a specific directory. |
| tar -xvf archive.tar file1 file2 | Extract specific files from the archive. |
4. packages management command
a. APT (Debian, Ubuntu and derivatives)
| sudo apt update | Refreshes package lists from repositories. |
| sudo apt upgrade | Installs the newest versions of all upgradable packages. |
| sudo apt install package | Installs a package. |
| sudo apt remove package | Removes a package but leaves config files. |
| sudo apt purge package | Removes a package and its configuration files. |
| sudo apt autoremove | Removes unnecessary dependencies. |
| apt list –installed | Lists all installed packages. |
| apt show package | Displays details about a package. |
b. YUM / DNF (CentOS, RHEL, Fedora)
| sudo yum update / sudo dnf update | Updates all packages to the latest version. |
| sudo yum install package | Installs a package. |
| sudo yum remove package | Removes a package. |
| sudo yum info package | Displays package information. |
| yum list installed | Lists installed packages. |
| yum clean all | Clears cache to free up space. |
5. rpm packages management command
| rpm -ivh package.rpm | Installs a package (-i = install, -v = verbose, -h = show hash/progress). |
| rpm -Uvh package.rpm | Upgrades a package (installs if not present, replaces if already installed). |
| rpm -Fvh package.rpm | Freshens a package (only upgrades if already installed). |
| rpm -e package | Erases (removes) a package. |
| rpm -q package | Queries if a package is installed. |
| rpm -qa | Lists all installed packages. |
| rpm -qi package | Displays detailed info about an installed package. |
| rpm -ql package | Lists all files installed by the package. |
| rpm -qf /path/to/file | Finds which package a particular file belongs to. |
| rpm -K package.rpm | Verifies the signature of a package file. |
6. ssh & remote Access
| ssh user@hostname | Connect to a remote server via SSH (replace user with the username and hostname with the IP or domain). |
| ssh -p 2222 user@hostname | Connect using a custom port (e.g., 2222). Useful if SSH is not on the default port (22). |
| ssh -i /path/to/key.pem user@hostname | Connect using a private key file (common for AWS and cloud VMs). |
| exit | Log out from the SSH session. |
| ssh-copy-id user@hostname | Copy your public key to a server for passwordless login. |
| scp file.txt user@hostname:/path/ | Copy a local file to a remote server using SCP. |
| scp user@hostname:/path/file.txt ./ | Download a file from the remote server to the local machine. |
| rsync -avz file.txt user@hostname:/path/ | Efficient file sync to a remote server using SSH. |
7. user management
a. User Account Commands
| adduser username | Adds a new user and prompts for password and user info (Debian/Ubuntu friendly). |
| useradd username | Adds a new user (lower-level; doesn’t prompt for password). |
| passwd username | Sets or changes the password for a user. |
| id username | Displays the user’s UID, GID, and group membership. |
| whoami | Shows the current logged-in username. |
| users | Shows a list of users currently logged into the system. |
| deluser username | Deletes a user account and optionally its home directory (Debian-based). |
| userdel username | Deletes a user account (more low-level, used in Red Hat-based distros). |
| userdel -r username | Deletes a user and their home directory. |
b. Group Management Commands
| groupadd groupname | Creates a new group. |
| groupdel groupname | Deletes an existing group. |
| usermod -aG groupname username | Adds a user to a group (append). Important: don’t forget the -a. |
| groups username | Lists the groups that the user belongs to. |
| gpasswd -d username groupname | Removes a user from a group. |
c. Modifying Users
| usermod -l newname oldname | Renames a user account. |
| usermod -d /new/home username | Changes the user’s home directory (use -m to move files). |
| usermod -s /bin/bash username | Changes the user’s default shell. |
| chage -l username | Displays password aging information (password expiration policy). |
| chage -E 2025-12-31 username | Set account expiration date. |
d. Locking and Disabling Users
| passwd -l username | Locks a user account (can’t login). |
| passwd -u username | Unlocks a user account. |
| usermod -L username | Another way to lock the account. |
| usermod -U username | Unlock the account. |
8. network command
a. Interface & Configuration
| ifconfig | Displays or configures network interfaces (older systems; superseded by ip command). |
| ip addr | Shows detailed network interface information (IP addresses, MAC, etc.). |
| ip link | Displays interface link status (up/down). |
| ip a | Short form of ip addr. |
| ip route | Shows current routing table. |
| nmcli device status | Displays network interface statuses (NetworkManager-managed systems). |
| ethtool interface | Displays or changes interface properties (e.g., speed/duplex). |
| hostname -I | Displays the system’s IP addresses (excluding loopback). |
| nmcli connection show | Lists network connections. |
b. Testing Connectivity
| ping hostname/IP | Tests connectivity to a host (ICMP packets). Use -c 4 to limit number of pings. |
| traceroute hostname/IP | Displays route packets take to reach a host. |
| mtr hostname/IP | Combines ping and traceroute for advanced route analysis (real-time). |
| curl -I http://example.com | Fetches HTTP headers to verify website/server responses. |
| wget example.com | Downloads files over HTTP/HTTPS (useful for testing connectivity). |
| nc -zv hostname port | Checks if a specific port is open (port scanning). |
| telnet hostname port | Tests network connectivity to a specific port (if Telnet is installed). |
c. Ports & Services
| ss -tuln | Lists listening ports and associated services (replaces netstat). |
| ss -plnt | Displays processes using TCP ports. |
| netstat -tulnp | Displays active connections and port usage (older; requires net-tools). |
| lsof -i | Lists open network connections with associated processes. |
| nmap hostname/IP | Scans remote host/network for open ports (requires nmap installation). |
d. DNS & Host Resolution
| dig domain.com | Queries DNS records for a domain (A, MX, TXT, etc.). |
| nslookup domain.com | Basic DNS lookup (older but still widely used). |
| host domain.com | Performs DNS lookups for a domain/IP. |
| resolvectl status | Displays DNS resolver status (Systemd-based systems). |
