/etc: Contains system configuration files. Example: /etc/fstab lists mounted filesystems./usr: Holds read-only user data like applications and libraries (e.g., /usr/bin/)./bin: Essential user binaries (e.g., ls, mkdir) available in single-user mode./sbin: System binaries (e.g., reboot, ifconfig) usually for root.cat /etc/passwd – view user infols /bin – list essential commands/var: Variable files like logs (/var/log), mail, and print spools./tmp: Temporary files. Cleared on reboot./home: User home directories (e.g., /home/alice)./boot: Files needed to boot, like kernel images and grub.ls /boot – shows kernel and bootloader files/proc: Provides process and kernel info as files (e.g., /proc/cpuinfo)./sys: Exposes hardware info and allows tuning of device parameters.cat /proc/meminfo – shows memory usagels /sys/class/net – shows network interfaces/opt: Optional add-on software packages./media: Mount points for removable media (USB, CD-ROM)./mnt: Temporary mounts for sysadmin use./dev: Device files representing hardware (e.g., /dev/sda).ls /dev – list devicesmount /dev/sdb1 /mnt – mount USB to /mntlintian or checksec on Debian-based systems check if software packages follow FHS guidelines.sudo apt install lintianlintian mypackage.deb – check FHS compliance of a package/dev/sda/dev/ttyls -l /dev/sdacrw-rw---- 1 root tty 4, 0 /dev/tty0/usr/bin/home/usernameecho "Hello" > ~/test.txt – writes to user's home/etc/fstab: Lists devices and their mount pointsmount/umount: Mount/unmount devicessudo mount /dev/sdb1 /mntcat /etc/fstab/run for runtime files. FHS is maintained by the Linux Foundation and adopted by all major distros./boot/efi.sudo fdisk -l – show partition table (MBR or GPT)grub-install/etc/default/grub and /boot/grub/grub.cfg (auto-generated)sudo grub-install /dev/sdasudo update-grub/etc/default/grub using the GRUB_CMDLINE_LINUX variable.GRUB_CMDLINE_LINUX="quiet splash"sudo update-grubdnsmasq, tftp-hpa, pxelinux.0grub or iPXE to specify ISO or HTTP boot source.initramfs: A small root filesystem loaded into memory before the real root system, used to load kernel modules.systemd (most common), SysVinit, Upstartlsinitramfs /boot/initrd.img-$(uname -r) – view contentsdmesg: Displays kernel ring buffer messages (early boot logs)journalctl: Displays system logs via systemd journaldmesg | grep errorjournalctl -b – logs from current bootsudo os-probersudo update-grub – adds Windows/Linux to GRUB menufdisk: CLI tool for MBR disks.parted: Handles both MBR and GPT.gdisk: Advanced tool for GPT disks.sudo fdisk /dev/sdasudo parted /dev/sdbsudo gdisk /dev/sdcsudo mkfs.ext4 /dev/sdb1sudo mkfs.xfs /dev/sdb2sudo mkfs.btrfs /dev/sdb3sudo mkswap /dev/sdX2sudo swapon /dev/sdX2free -h – see active swap/etc/fstab ensures persistent mounts.sudo mount /dev/sdb1 /mntsudo umount /mntcat /etc/fstabsudo lvextend -L +1G /dev/myvg/mylvsudo resize2fs /dev/myvg/mylvmdadm.sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc/etc/fstab:/dev/sdb1 /home ext4 defaults,usrquota,grpquota 0 2sudo quotacheck -cum /homesudo quotaon /homesudo edquota usernamefsck for ext2/3/4xfs_repair for XFSsudo fsck /dev/sdb1sudo xfs_repair /dev/sdb2sudo mount -t nfs 192.168.1.10:/share /mntsudo mount -t cifs //server/share /mnt -o user=guestAPT (Debian/Ubuntu):sudo apt updatesudo apt install nginxDNF/YUM (Fedora/Red Hat):sudo dnf install httpdZypper (openSUSE):sudo zypper install apache2rpm -ivh package.rpm – installrpm -qa – list installed packagessudo dpkg -i package.debdpkg -l/etc/apt/sources.list and /etc/apt/sources.list.d//etc/yum.repos.d/*.repozypper repossudo add-apt-repository ppa:deadsnakes/ppasudo dnf config-manager --add-repo URL/etc/apt/preferencessudo apt-mark hold packagenameyum history listyum history undo IDsudo snap install vlcflatpak install flathub org.gimp.GIMPchmod +x file.AppImage && ./file.AppImagegpg --verify file.sig filesha256sum filenamesha256sum -c checksum.txtsudo apt --fix-broken installdnf repoquery --requiressudo apt install unattended-upgradessudo dpkg-reconfigure unattended-upgradesdnf-automatic service can be enabled.docker pull ubuntu:latestdocker build -t myapp .docker imagesbash: Bourne Again SHell, default in many Linux distros.sh: Original Bourne shell, basic scripting.zsh: Extended shell with better features like autocomplete and themes.echo $SHELL – shows current shellchsh -s /bin/zsh – change default shell to zshNAME="Majid"echo $NAMEhistoryalias ll="ls -la"cmd1 && cmd2 runs cmd2 if cmd1 succeedscmd1 || cmd2 runs cmd2 if cmd1 fails(cd /tmp && ls) runs in a subshellcommand > file (overwrite),command >> file (append),command 2>&1 redirects stderr to stdoutls -l | grep ".txt"tee writes output to file and stdout:ls | tee file.txtxargs build argument lists:find . -name "*.log" | xargs rmecho $PATHexport PATH=$PATH:/new/pathgrep: Search text patterns:grep "error" logfilesed: Stream editor, substitution:sed 's/old/new/g' file.txtawk: Text processing and reporting:awk '{print $1}' file.txtfind: Search files by name, size, date:find / -name "file.txt"locate: Fast file search using database:locate file.txtwhereis: Locate binary/source/man pages:whereis lsstat file.txt: Shows detailed file info (size, permissions, timestamps)file file.txt: Shows file typecut, sort, uniq, head, tail manipulate text streams.cat file.txt | sort | uniq -c – count unique lines~/.bashrc: User-specific shell settings./etc/profile: System-wide environment variables and startup scripts.source ~/.bashrc.service for services.timer for scheduled jobs.socket for socketssudo systemctl start nginx.servicesudo systemctl enable nginx.service (start on boot)sudo systemctl disable apache2.servicesudo systemctl status sshd.servicecron: daemon that runs scheduled jobscrontab -eat: schedule one-time jobs0 3 * * * /usr/bin/backup.shjournalctl -u nginx (nginx logs)journalctl -b (current boot logs)docker run -d --name nginx nginxcommand & runs job in backgroundjobs lists background jobsfg %1 brings job 1 to foregroundnohup command & runs job immune to hangupsulimit -a shows current limitsulimit -n 1024[Timer]OnBootSec=5minOnUnitActiveSec=5minsystemd-analyze to profile boot time:systemd-analyze blameRequires=, After=, Before=lsmod: Lists currently loaded modulesinsmod: Insert a module (requires exact path)rmmod: Remove a loaded modulemodprobe: Smart module loader handling dependencieslsmod | grep usbsudo modprobe snd_hda_intel/etc/modules-load.d/*.conf or /etc/modules to load at boot./proc/modules: Info on loaded modules/sys: Kernel device info, e.g., /sys/class/net/eth0/dev/sda)mknod/etc/udev/rules.d/ customize behavior.lsusblspcilsblk/lib/firmware.dmesg | grep module_namemodprobe -r and reload modules.sudo apt install linux-image-ip addr add 192.168.1.10/24 dev eth0ip route showip route add default via 192.168.1.1/etc/dhcp/dhclient.conf or NetworkManager./etc/resolv.conf.ping: Test connectivity.traceroute: Trace packet route.netstat: View open connections and ports.host: Simple DNS lookup.dig: Detailed DNS queries.nslookup: Interactive DNS client.ip link or via cloud-init in cloud environments.iptables: Classic firewall tool.nftables: Newer replacement for iptables.ufw: User-friendly frontend.scp file.txt user@remote:/path/rsync -avz /local/dir user@remote:/remote/dirip a – view interfacesping 8.8.8.8traceroute google.comsudo iptables -LX11: Traditional display server protocol.Wayland: Modern replacement for X11 with improved security and performance.sudo apt install ubuntu-gnome-desktopsudo dnf groupinstall "KDE Plasma Workspaces"locale to view settings.sudo timedatectl set-timezone America/Torontosudo dpkg-reconfigure locales or edit /etc/locale.conf.setxkbmap us/etc/default/keyboard./usr/share/fonts or ~/.fonts.fc-cache -fv to update font cache.xrandr to list and set resolutions:xrandr --output HDMI1 --mode 1920x1080orca.tigervnc, tightvncsudo apt install xrdpgnome-system-monitor, kde-system-monitor, or htop.cat ~/.xsession-errorssudo systemctl restart gdmtop: Real-time process viewerhtop: Interactive, improved topvmstat: Reports virtual memory statsiostat: Disk I/O statstop or htop to identify processes with high CPU or memory usage.iostat -xz 1.cat /sys/block/sda/queue/scheduler and select scheduler (cfq, noop, deadline).swapon -svmstat 1.nice -n 10 commandrenice -n 5 -p PIDlsof -p PIDlsof /var/log/syslogulimit for shell resource limits.cgroups limit resources for groups of processes.sysctl -asudo sysctl -w net.ipv4.ip_forward=1/etc/sysctl.conf.sar (from sysstat package) for long-term monitoring.ps aux | grep Z to find zombies.useradd, adduser create new users:sudo useradd -m usernamesudo passwd username sets password.sudo groupadd developerssudo usermod -aG developers username/etc/skel for default files.chage -l username/etc/sudoers with visudo for safe syntax.username ALL=(ALL) ALLsetfacl -m u:username:rwx /pathgetfacl /pathusermod, groupmod.www-data) run services with limited privileges.sudo usermod -L username locks account;sudo usermod -U username unlocks.who, w, last to track logins.rsync -av --delete /source/ /backup/tar czvf backup.tar.gz /foldercrontab -e to add backup jobs:0 2 * * * /usr/local/bin/backup.shtar tzvf backup.tar.gzlvcreate -L1G -s -n snap1 /dev/vg0/lv0rclone or commercial cloud services.gpg -c backup.tar.gzsudo apt install qemu-kvm libvirt-daemonvirt-manager for GUI management.docker run -d nginxdocker ps lists running containersdocker stop container_iddocker pull ubuntulxc and lxd commands.journalctl -u libvirtd, verify CPU virtualization support.curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"unzip awscliv2.zipsudo ./aws/installjournalctl, logrotate.sudo smartctl -a /dev/sdastress-ng or sysbench for CPU load testing.lm-sensors, hddtemp.sudo sensorsfwupd.tlp, UPS monitoring via apcupsd.lshw, dmidecode.lspci, lsusb, check kernel logs.dmesg | lessls -Zchcon -t httpd_sys_content_t /var/www/html/index.htmlausearch, sealert tools.sudo aa-statuslogrotate.grep, awk, or tools like ElasticSearch.kubectl get pods, kubectl logs podnamesudo apt remove package_namesystemctl list-unit-files --type=servicesudo systemctl disable service_name/etc/ssh/sshd_config to disable root login:PermitRootLogin nosudo apt update && sudo apt upgradesetfacl -m u:username:rwx /filegetfacl /filels -Z /pathchcon.audit2allow to generate policy rules.aa-status, aa-complain, aa-enforce.ausearch, dmesg.sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPTsudo iptables -P INPUT DROPfirewall-cmd --list-allsudo ufw allow 80/tcpsudo iptables -A INPUT -j LOG --log-prefix "iptables-drop: "sudo iptables -L -vgpg -c file.txtgpg file.txt.gpgopenssl req -new -newkey rsa:2048 -nodes -keyout key.pem -out req.csrsudo cryptsetup luksFormat /dev/sdb1auditctl -w /etc/passwd -p wa -k passwd_changesausearch and aureport.apt, yum, or dnf.unattended-upgrades or WSUS.#!/bin/bash to specify interpreter.name="value", access with $name.my_func() { echo "Hello"; }$1, $2,....exit and check status with $?.bash -x script.sh to trace execution.read, echo, and redirection.#!/bin/bash
backup_dir="/backup/$(date +%F)"
mkdir -p "$backup_dir"
cp -r /important/data/* "$backup_dir"/
echo "Backup completed at $(date)"
git initgit clone <url> to copy remote repos.git add file.txtgit commit -m "Message"git branch new-featuregit checkout new-featuregit merge new-featuregit log to view commit history.git remote add origin <url>git push origin maingit checkout -- file.txt to discard local changes.#!/usr/bin/env python3 shebang.def.open('file.txt', 'r').try-except blocks for errors.venv.#!/usr/bin/env python3
filename = 'sample.txt'
with open(filename) as f:
for line in f:
print(line.strip())python3 script.pycrontab files.minute hour day month weekday commandcrontab -e to edit the current user’s jobs.> /path/to/log 2>&1 for logging.0 2 * * * /home/user/backup.sh (daily backup at 2am).sudo apt install docker.io podmandocker run hello-world, docker ps.podman run alpine.docker-compose.yml.resource "aws_instance" "web" {
ami = "ami-123456"
instance_type = "t2.micro"
}terraform apply and terraform destroy./boot/grub/grub.cfg or /etc/default/grub.sudo grub-install /dev/sda
sudo update-grub/var/log.systemctl status.journalctl -b shows current boot logs.smartctl -a /dev/sdX to view SMART data.fdisk -l or parted./etc/fstab syntax and device UUIDs.fsck for ext filesystems, xfs_repair for XFS.vgdisplay, lvdisplay.cat /proc/mdstat to check RAID status.df -h and du.ip a or ifconfig.ip route.ping, traceroute, mtr./etc/resolv.conf, use dig or nslookup.ip link set dev eth0 down and up.journalctl -u NetworkManager or system logs.systemctl status <service>.journalctl -u <service> or /var/log.systemctl restart <service>.Restart=always in systemd unit files.systemctl is-active.gdb.dmesg or serial console.fsck on unmounted partitions.testdisk, photorec.noatime, data=writeback.ausearch, journalctl.semanage, aa-status.setroubleshoot, audit2allow.top, htop, iotop.perf, strace.tcpdump, strace, lsof.ping, traceroute.mosh for improved experience.scp, sftp.top, vmstat remotely./var/log directory.logrotate.ausearch, auditctl.testdisk, photorec.memtest86 for RAM, smartctl for disks.lm-sensors.stress-ng.semanage and audit2allow.aa-complain, aa-enforce.setroubleshoot, audit2allow.rsyslog or syslog-ng.kubectl logs, kubectl describe.apt, yum, dnf.