Essential Linux Commands and System Fundamentals
Program Components
A typical program consists of:
- Binary executables
- Shared libraries (non-executable on their own, only loaded when called)
- Configuration files
- Documentation or help files
Command Structure
The general syntax is: COMMAND [OPTIONS] [ARGUMENTS]
Command Execution
Commands are executable binaries that may depend on shared libraries. Common locations include:
- User commands:
/bin,/usr/bin,/usr/local/bin - Administrative commands:
/sbin,/usr/sbin,/usr/local/sbin - Libraries (32-bit):
/lib,/usr/lib,/usr/local/lib - Libraries (64-bit):
/lib64,/usr/lib64,/usr/local/lib64
Not all commands correspond to a file in these directories—some are shell built-ins.
The PATH environment variable defines the search order for command resolution (left to right). View it with:
echo $PATH
Options
- Short form:
-l,-d; combinable as-ld - Long form:
--help,--human-readable; not combinable - Some options accept parameters (e.g.,
-t 1909131212)
Arguments
Specify targets of the command (e.g., files or directories). Multiple arguments are space-separated:
ls -ld /var /etc
Accessing Help
- Built-in commands:
help COMMAND - External commands:
COMMAND --help- Manual pages:
man COMMAND
Manual sections:
- User commands
- System calls
- Library functions
- Special files
- File formats
- Administration tools
Within man, navigation includes:
- Space: next page
b: previous page/keyword: search forward?keyword: search backwardq: quit
Core Commands
Directory Navigation
cd: home directorycd ~user: user’s homecd -: toggle between last and current directory
Relevant variables:
$PWD: current directory$OLDPWD: previous directory
Listing Files (ls)
Common flags:
-a: show hidden files-l: detailed listing-h: human-readable sizes-d: list directory itself-R: recursive listing
Example output:
-rw-r--r--. 1 root root 8957 Oct 14 19:34 boot.log
Breakdown:
-: regular file (d= directory,l= symlink, etc.)rw-r--r--: permissions for owner/group/others1: hard link countroot root: owner and group8957: size in bytes- Timestamp and filename
File Viewing
cat file: output entire file-n: line numbers-E: show$at line ends
tac file: reverse line orderhead -n 10 file: first 10 linestail -n 10 file: last 10 linesless file: interactive paging (preferred overmore)
Echo and Quoting
echo -e "line1\nline2"
-e: interpret escape sequences- Single quotes
'...': literal (no variable expansion) - Double quotes
"...": allow variable substitution ${VAR}: explicit variable reference
System Control
- Shutdown:
shutdown -h now - Reboot:
shutdown -r +5 "Update" - Cancel:
shutdown -c
Time Management
- Hardware clock ↔ system clock:
hwclock --hctosys(sync system from hardware)hwclock --systohc(sync hardware from system)
Command Location and Aliasing
which ls: shows full path of executablewhereis bash: locates binary, source, and manual- Aliases (session-only):
alias ll='ls -l' unalias ll
Filesystem Hierarchy Standard (FHS)
Key directories:
/bin,/sbin: essential binaries/boot: kernel and bootloader files/dev: device files (block/character)/etc: static configuration/home: user home directories/root: admin home/lib,/lib64: shared libraries/media,/mnt: mount points/opt: optional software/tmp: temporary files (world-writable)/usr: read-only shared data (bin, lib, share, local, etc.)/var: variable data (logs, spools, caches)/proc,/sys: virtual filesystems exposing kernel/process info
File Types
-: regular filed: directoryb: block devicec: character devicel: symbolic linkp: named pipes: socket
Devices use major/minor numbers to identify type and instance.
Bash Features
Command History
history: list recent commands!5: re-run command #5!ssh: re-run last command starting with "ssh"Esc + .: insert last argument of previous command
Brace Expansion
mkdir -p /tmp/x/{y1/{a,b},y2}→ creates nested dirstouch {a,b}_{x,y}.txt→a_x.txt,a_y.txt,b_x.txt,b_y.txt
Exit Status
- Success:
0 - Failure:
1–255 - Check with:
echo $?
Keyboard Shortcuts
Ctrl+a: beginning of lineCtrl+e: end of lineCtrl+u: delete to startCtrl+k: delete to endCtrl+l: clear screen
File Operations
Metadata Inspection
stat file: shows access (atime), modify (mtime), and change (ctime) timestamps
Timestamp Modification
touch -a file: update access timetouch -m file: update modify timetouch -t [[CC]YY]MMDDhhmm[.ss] file
Copying (cp)
- Single file:
cp src dest - Recursive:
cp -r dir1 dir2 - Archive mode (preserves all attributes):
cp -a src dest - Interactive:
cp -i src dest
Moving/Renaming (mv)
mv old new- Supports
-i(prompt) and-f(force)
Deletion (rm)
- Files:
rm file - Directories:
rm -r dir - Forceful removal:
rm -rf dir
⚠️ Caution: rm -rf /* is catastrophic. Prefer moving files to a trash directory instead of immediate deletion.