Common Linux commands (ls, cd, cp, mv, rm, etc.)

1. Basic Linux Commands

lsList files in a directory
cdChange directory
pwdShow current directory =path
cpCopy files or directories
mvMove or rename files
rmRemove files or =directories
mkdirCreate a new directory
rmdirRemove empty directory
touchCreate empty file
catView contents of a file
nano / vimText editors in terminal
chmodChange file permissions
chownChange file owner
findFind files by name or type
grepSearch text in files
df -hDisk usage summary (human-readable)
du -shDirectory size
ps auxList running processes
top / htopReal-time system monitoring
killKill a process by PID
manView manual pages for commands
clearClear terminal screen
exitClose terminal session

2. File permissions & ownership

ls -lLists files with permissions, ownership, size, and modification date.
chmod [options] mode fileChanges permissions of a file or directory.
chmod 755 script.shSets read, write, and execute for owner; read and execute for group and others.
chmod u+x fileAdds execute permission to the user (owner).
chmod g-w fileRemoves write permission from the group.
chmod o=r fileSets read-only for others.

Group Management  

chgrp group fileChanges the group ownership of a file.
groupsLists groups the current user belongs to.
usermod -aG group userAdds 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 file2Create 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.tarExtract contents of a .tar file.
tar -xvf archive.tarSame as above, with verbose output.
tar -xzf archive.tar.gzExtract a .tar.gz archive.
tar -xjf archive.tar.bz2Extract a .tar.bz2 archive.
tar -xvf archive.tar -C /target/dir/Extract to a specific directory.
tar -xvf archive.tar file1 file2Extract specific files from the archive. 

4. packages management command   

a. APT (Debian, Ubuntu and derivatives)  

sudo apt updateRefreshes package lists from repositories.
sudo apt upgradeInstalls the newest versions of all upgradable packages.
sudo apt install packageInstalls a package.
sudo apt remove packageRemoves a package but leaves config files.
sudo apt purge packageRemoves a package and its configuration files.
sudo apt autoremoveRemoves unnecessary dependencies.
apt list –installedLists all installed packages.
apt show packageDisplays details about a package.

b. YUM / DNF (CentOS, RHEL, Fedora)  

sudo yum update / sudo dnf updateUpdates all packages to the latest version.
sudo yum install packageInstalls a package.
sudo yum remove packageRemoves a package.
sudo yum info packageDisplays package information.
yum list installedLists installed packages.
yum clean allClears cache to free up space.

5. rpm packages management command

rpm -ivh package.rpmInstalls a package (-i = install, -v = verbose, -h = show hash/progress).
rpm -Uvh package.rpmUpgrades a package (installs if not present, replaces if already installed).
rpm -Fvh package.rpmFreshens a package (only upgrades if already installed).
rpm -e packageErases (removes) a package.
rpm -q packageQueries if a package is installed.
rpm -qaLists all installed packages.
rpm -qi packageDisplays detailed info about an installed package.
rpm -ql packageLists all files installed by the package.
rpm -qf /path/to/fileFinds which package a particular file belongs to.
rpm -K package.rpmVerifies the signature of a package file.

6. ssh & remote Access

ssh user@hostnameConnect to a remote server via SSH (replace user with the username and hostname with the IP or domain).
ssh -p 2222 user@hostnameConnect using a custom port (e.g., 2222). Useful if SSH is not on the default port (22).
ssh -i /path/to/key.pem user@hostnameConnect using a private key file (common for AWS and cloud VMs).
exitLog out from the SSH session.
ssh-copy-id user@hostnameCopy 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 usernameAdds a new user and prompts for password and user info (Debian/Ubuntu friendly).
useradd usernameAdds a new user (lower-level; doesn’t prompt for password).
passwd usernameSets or changes the password for a user.
id usernameDisplays the user’s UID, GID, and group membership.
whoamiShows the current logged-in username.
usersShows a list of users currently logged into the system.
deluser usernameDeletes a user account and optionally its home directory (Debian-based).
userdel usernameDeletes a user account (more low-level, used in Red Hat-based distros).
userdel -r usernameDeletes a user and their home directory.

b. Group Management Commands  

groupadd groupnameCreates a new group.
groupdel groupnameDeletes an existing group.
usermod -aG groupname usernameAdds a user to a group (append). Important: don’t forget the -a.
groups usernameLists the groups that the user belongs to.
gpasswd -d username groupnameRemoves a user from a group.

c. Modifying Users  

usermod -l newname oldnameRenames a user account.
usermod -d /new/home usernameChanges the user’s home directory (use -m to move files).
usermod -s /bin/bash usernameChanges the user’s default shell.
chage -l usernameDisplays password aging information (password expiration policy).
chage -E 2025-12-31 usernameSet account expiration date.

d.  Locking and Disabling Users  

passwd -l usernameLocks a user account (can’t login).
passwd -u usernameUnlocks a user account.
usermod -L usernameAnother way to lock the account.
usermod -U usernameUnlock the account.

8. network command

a. Interface & Configuration  

ifconfigDisplays or configures network interfaces (older systems; superseded by ip command).
ip addrShows detailed network interface information (IP addresses, MAC, etc.).
ip linkDisplays interface link status (up/down).
ip aShort form of ip addr.
ip routeShows current routing table.
nmcli device statusDisplays network interface statuses (NetworkManager-managed systems).
ethtool interfaceDisplays or changes interface properties (e.g., speed/duplex).
hostname -IDisplays the system’s IP addresses (excluding loopback).
nmcli connection showLists network connections.

b. Testing Connectivity  

ping hostname/IPTests connectivity to a host (ICMP packets). Use -c 4 to limit number of pings.
traceroute hostname/IPDisplays route packets take to reach a host.
mtr hostname/IPCombines ping and traceroute for advanced route analysis (real-time).
curl -I http://example.comFetches HTTP headers to verify website/server responses.
wget example.comDownloads files over HTTP/HTTPS (useful for testing connectivity).
nc -zv hostname portChecks if a specific port is open (port scanning).
telnet hostname portTests network connectivity to a specific port (if Telnet is installed).

c. Ports & Services  

ss -tulnLists listening ports and associated services (replaces netstat).
ss -plntDisplays processes using TCP ports.
netstat -tulnpDisplays active connections and port usage (older; requires net-tools).
lsof -iLists open network connections with associated processes.
nmap hostname/IPScans remote host/network for open ports (requires nmap installation).

d. DNS & Host Resolution  

dig domain.comQueries DNS records for a domain (A, MX, TXT, etc.).
nslookup domain.comBasic DNS lookup (older but still widely used).
host domain.comPerforms DNS lookups for a domain/IP.
resolvectl statusDisplays DNS resolver status (Systemd-based systems).

Leave a Reply

Your email address will not be published. Required fields are marked *