Linux Commands, Configuration Files, and Components
Unit 3: macOS and Linux. Lesson 12 of 41 in APlus Academy Core 2.
Linux support on the exam is a list of commands and files. Learn each by its job, and the handful of switches and rules that come with it.
The shell and the rules
Commands are case-sensitive, and so are file names. ~ is your home directory, / the root of the filesystem, . the current directory, .. the parent. Options start with a dash: ls -la. Anything that changes the system needs root rights through sudo.
File management
lslists files;ls -llong form with permissions, owner, size, date;-aincludes hidden files (names starting with a dot).pwdprints the working directory.cdchanges it.mvmoves or renames;cpcopies (cp -rfor directories);rmremoves (rm -rrecursive,-fwithout asking; there is no recycle bin).chmodchanges permissions. Each file has read, write, and execute for owner, group, and others. Numerically r is 4, w is 2, x is 1, sochmod 755 script.shgives the owner everything and others read and execute,chmod 644 filegives the owner read and write and others read only; symbolicallychmod +x script.shadds execute.chownchanges the owner and group:chown user:group file, with-Rfor a tree.grepsearches text:grep -i error /var/log/syslog(case-insensitive),-rrecursive through directories.findlocates files:find / -name "*.conf", by size, age, or owner.
Filesystem management
fsckchecks and repairs a filesystem, run on an unmounted volume (from recovery or on a data disk), like chkdsk.mountattaches a filesystem to a directory:mount /dev/sdb1 /mnt/usb;umountdetaches it;mountalone lists what is mounted.
Administrative
suswitches to another user, by default root, with that account's password; the whole shell becomes root, which is risky.sudoruns one command as root using your own password, logs it, and is the preferred method:sudo apt update. Users must be in the sudo (or wheel) group.- The root account has unlimited power (user ID 0); many distributions disable its direct login and expect sudo.
Package management
apton Debian, Ubuntu, and their relatives:sudo apt updaterefreshes the package lists,sudo apt upgradeinstalls updates,sudo apt install package,sudo apt remove package.dnfon Fedora, Red Hat, and relatives (successor to yum):sudo dnf install package,sudo dnf update.
Packages come from the distribution's repositories, signed and dependency-resolved; that is Linux's app store.
Network
ipreplaced ifconfig:ip addr(orip a) shows addresses,ip routethe routes and gateway,ip linkthe interfaces.pingas in Windows, but continuous by default (Ctrl+C stops;-c 4sends four).curlfetches a URL from the command line; tests web services and downloads files.digqueries DNS in detail (answer, server, timing); nslookup exists too.traceroutelists the hops (tracert's cousin).
Informational
man commandopens the manual page;qquits.cat fileprints a file;lesspages through it.topshows live processes with CPU and memory (htop is friendlier);pslists processes,ps auxfor everything;kill PIDends one.du -sh foldershows how much space a directory uses;df -hshows free space per mounted filesystem. "Disk full" starts with df, then du to find the culprit.
Text editors
nano is the beginner-friendly editor: Ctrl+O saves, Ctrl+X exits, the shortcuts are on screen. vi and vim are everywhere but modal (press i to insert, Esc then :wq to save and quit).
Common configuration files
/etc/passwd: one line per user account: name, user ID, group ID, home directory, shell. World-readable./etc/shadow: the hashed passwords and aging rules; readable only by root./etc/hosts: static name-to-address mappings checked before DNS; the place a manual override or a malware redirect hides./etc/fstab: filesystems to mount at boot, with mount points and options; a typo here can stop the boot./etc/resolv.conf: the DNS servers and search domain (often managed by a service such as systemd-resolved or NetworkManager).
OS components
- The kernel is the core that manages hardware, memory, and processes; its version shows with
uname -r. - The bootloader (GRUB on most distributions) loads the kernel; its menu lets you pick a kernel or recovery mode.
- systemd is the init system and service manager:
systemctl status service,systemctl start,stop,restart,enable(start at boot),disable;journalctlreads its logs.
Linux Commands, Configuration Files, and Components, explained slowly
Linux as a toolbox
A Linux session is a set of small tools chained together. The exam lists the tools and asks what each does, plus the files and components that hold the system together. Organize them by category and keep the quirks (case sensitivity, no recycle bin, numeric permissions) next to them.
Files and directories
command does example ls list ls -la (long, all) pwd print working directory cd change directory cd ~ home; cd .. up mv move or rename mv old.txt new.txt cp copy cp -r dir backup (recursive) rm remove rm -rf dir (recursive, forced; no undo) chmod change permissions chmod 755 run.sh; chmod +x run.sh chown change owner and group chown -R alice:staff project grep search text grep -ri "error" /var/log find find files find / -name "*.conf" 2>/dev/null cat print a file cat /etc/hosts
Permissions decoded
-rwxr-xr-- 1 alice staff 1234 Sep 7 file.sh ^^^^^^^^^ owner rwx = 7; group r-x = 5; others r-- = 4 -> chmod 754 r = 4, w = 2, x = 1; add them per class; owner, group, others in that order 755: owner everything, everyone else read and execute (scripts, programs) 644: owner read and write, everyone else read (documents) 700: owner only (private keys)
A directory needs x to be entered. chown user:group changes ownership; only root (via sudo) can give files away.
Disks and mounts
fsck checks and repairs a filesystem and must run on an unmounted volume (boot to recovery for the root filesystem). mount attaches a device to a directory (mount /dev/sdb1 /mnt/usb); umount detaches; mount with no arguments lists everything mounted. df -h shows free space per mounted filesystem; du -sh path shows what a directory consumes. /etc/fstab lists what mounts at boot.
Root, su, sudo
tool what happens when root the superuser, UID 0, can do anything never log in as root for daily work su switch user; su alone becomes root with root's password; the whole shell is root rare; many distributions lock root's password sudo run one command as root with your own password; logged; membership in sudo or wheel group the normal way: sudo apt update
Packages
apt (Debian, Ubuntu, Mint): sudo apt update refreshes the index, sudo apt upgrade applies updates, sudo apt install name, sudo apt remove name. dnf (Fedora, RHEL, Rocky; yum's successor): sudo dnf install name, sudo dnf update. Packages are signed and dependencies resolved from repositories; snap and flatpak are cross-distribution alternatives.
Network
command does ip addr addresses (ip a); ip route gateway and routes; ip link interfaces up or down ping reachability; continuous by default; -c 4 for four packets curl fetch a URL: curl https://example.com; test an API; download with -O dig DNS query with full detail: dig example.com; dig @8.8.8.8 example.com MX traceroute hops to a destination
Processes and space
top shows live processes sorted by CPU (q quits); ps aux lists all; kill PID ends one (kill -9 forces). du and df as above; a full disk stops logins and services, so df -h is the first command on a sick server.
Editors and files
nano: arrow keys, Ctrl+O write out, Ctrl+X exit, Ctrl+W search; the shortcuts are printed at the bottom. vi/vim: i to insert, Esc, :wq to save and quit, :q! to abandon.
file holds note /etc/passwd users: name:x:uid:gid:comment:home:shell readable by all; the x means the hash is in shadow /etc/shadow hashed passwords and aging root only /etc/hosts static name-to-IP mappings checked before DNS; malware and overrides live here /etc/fstab filesystems to mount at boot a bad line can stop the boot /etc/resolv.conf DNS servers (nameserver lines) and search domain may be generated by a resolver service
Components
The kernel manages hardware, memory, and processes (uname -r shows the version). The bootloader, GRUB on most systems, loads the kernel and offers a menu (older kernels, recovery mode). systemd starts and supervises services: systemctl status sshd, systemctl restart sshd, systemctl enable sshd (start at boot), systemctl disable; journalctl -u sshd reads its log.
Worked examples
- "A script will not run: Permission denied." chmod +x script.sh, then ./script.sh.
- "A web server on Ubuntu needs a package." sudo apt update && sudo apt install nginx; sudo systemctl enable --now nginx.
- "The server is out of space." df -h to find the full filesystem, du -sh /var/log/* to find the culprit, then rotate or delete.
- "A hostname resolves to the wrong address only on this machine." cat /etc/hosts; remove the stale line; cat /etc/resolv.conf to confirm the DNS server.
- "A service is down after reboot." systemctl status name; journalctl -u name; systemctl enable name if it was never enabled.
How the exam asks it
- "Which command changes file permissions?" chmod. "Which changes the owner?" chown.
- "Which command lets a user run one command as root?" sudo.
- "Which package manager is used on Ubuntu?" apt. "On Fedora?" dnf.
- "Which command shows IP addresses on a Linux system?" ip (ip addr).
- "Which command shows free disk space?" df. "Disk usage of a folder?" du.
- "Which file contains hashed passwords?" /etc/shadow.
- "Which file defines filesystems mounted at boot?" /etc/fstab.
- "Which component manages services on modern Linux?" systemd.
What to memorize
- The command tables and the chmod numbers.
- su versus sudo versus root; apt versus dnf.
- The five /etc files; kernel, bootloader (GRUB), systemd and systemctl.