What is Unix?
Unix is a family of multitasking - multiuser operating systems originally developed at Bell Labs in the 1960s-70s. Key characteristics: everything is a file + hierarchical file system + small modular programs that do one thing well + shell scripting + pipes for combining commands. Linux is a Unix-like OS (not Unix itself). macOS is Unix-certified. Foundation of modern computing including Android - macOS - cloud servers
What is Linux?
Linux is a free open-source Unix-like operating system kernel created by Linus Torvalds in 1991. The full OS (Linux kernel + GNU tools) is often called GNU/Linux. Distributions (distros): Ubuntu + CentOS/RHEL + Debian + Fedora + Alpine + Amazon Linux. Dominates: web servers + cloud + Android + embedded systems. Kernel is at the core - manages hardware - processes - memory - file system
What is the Kernel in Unix/Linux?
Kernel is the central core component of the OS - the first program loaded on startup. Responsibilities: memory management + process scheduling + hardware communication (device drivers) + file system management + system calls interface. Key: kernel does NOT directly interact with users - it spawns a shell for user interaction. Has protected memory area that no process can overwrite. Linux kernel: monolithic with loadable modules
What is a Shell in Unix?
Shell is a user interface (command line interpreter) that provides access to Unix/Linux services. Takes user commands -> sends to OS for execution -> returns output. Two types: interactive (user types commands) + non-interactive (runs scripts). Also provides: environment setup + variables + scripting language + pipes + I/O redirection. Kernel spawns a shell for each user session
What are the different shells in Unix?
Bourne shell (sh - original Unix shell) + Bourne Again Shell (bash - most common Linux shell - enhanced sh) + Korn shell (ksh - commercial Unix) + Z shell (zsh - default on macOS since Catalina - powerful) + C shell (csh - C-like syntax) + Enhanced C shell (tcsh - improved csh) + Fish shell (user-friendly - modern). Check current shell: echo $SHELL. Change shell: chsh -s /bin/zsh
What are the main responsibilities of a Unix Shell?
Program execution (run commands and scripts) + Environment setup (define env variables with export) + Interpreter (built-in scripting language - if/for/while/case) + Pipeline (connect commands with pipe | - output of one becomes input of next) + I/O redirection (> stdout redirect - < stdin redirect -»_space; append - 2> stderr) + Job control (background/foreground processes) + History and tab completion
What is the difference between Multi-tasking and Multi-user environments?
Multi-tasking: one user can run multiple tasks simultaneously - OS executes them at the same time (time-slicing). Multi-user: multiple users can interact with the OS simultaneously - each gets their own session and process space. Unix/Linux is BOTH multitasking AND multiuser. Windows Server is multiuser. Embedded systems may be single-user single-tasking
What is the difference between the Unix Kernel and Shell?
Kernel: core of OS - manages hardware resources - protected memory - runs in kernel space - system calls interface - processes everything at OS level. Shell: user-facing interface - interprets user commands - runs in user space - sends requests to kernel via system calls. User -> Shell -> Kernel -> Hardware. Shell is just one of many programs that use the kernel
MEMORY BOOSTER: Unix/Linux fundamentals
Kernel = core OS (memory + processes + hardware + protected). Shell = user interface (CLI + scripting + pipes + I/O redirection). Shells: sh (original) + bash (most common Linux) + zsh (macOS default) + ksh + csh. User -> Shell -> Kernel -> Hardware. Unix is both multitasking (multiple tasks per user) AND multiuser (multiple users simultaneously). Everything in Unix is a file
What is the Unix file system hierarchy?
Root (/) is the top of the hierarchy. Key directories: /bin (essential binaries - ls - cp - rm) + /etc (config files) + /home (user home dirs) + /var (variable data - logs) + /tmp (temporary files) + /usr (user programs + libraries) + /lib (shared libraries) + /proc (virtual - process info) + /dev (device files) + /opt (optional software) + /root (root user home) + /boot (boot files + kernel)
What is an Inode in Unix?
An Inode (Index Node) is a data structure in the Unix file system that stores file metadata. Contains: file type + permissions + owner + group + size + timestamps (created/modified/accessed) + number of hard links + pointers to data blocks on disk. Does NOT contain: filename (stored in directory entry) + file content. Each inode has a unique number. ls -i shows inode number. df -i shows inode usage
What is the difference between absolute path and relative path?
Absolute path: complete path from root directory (/). Always starts with /. Works from any location. Example: /var/log/nginx/access.log. Relative path: path relative to current working directory. Does NOT start with /. . = current dir. .. = parent dir. ~ = home dir. Example: ./logs/app.log or ../config/settings. pwd shows current absolute path. cd changes directory using either type
What is the difference between a hard link and a soft link (symlink)?
Hard link: another directory entry pointing to the SAME inode (same data on disk). Same file - different names. Cannot span file systems. Cannot link directories. Deleting original keeps data (multiple references to inode). Soft link (symlink): a special file containing a PATH to the target. Can span file systems. Can link directories. If target deleted -> broken symlink. ln = hard link. ln -s = soft link. ls -l shows -> for symlinks
What is the first character in ls -l output?
ls -l first character shows file type: - (regular file) + d (directory) + l (symbolic link) + b (block special file - disk) + c (character special file - terminal) + s (socket) + p (named pipe / FIFO). Following 9 characters = permissions (rwxrwxrwx = owner/group/other). Example: -rwxr-xr– = regular file - owner rwx - group r-x - others r–
What are Unix file permissions?
Three levels: owner (u) + group (g) + others (o). Three permission types: r (read=4) + w (write=2) + x (execute=1). chmod changes permissions: chmod 755 file (rwxr-xr-x) + chmod u+x file (add execute for owner) + chmod go-w file (remove write for group+others). chown changes owner: chown user:group file. Special bits: setuid (s on user x) + setgid (s on group x) + sticky bit (t on other x)
What is the difference between / and ~ in Unix?
/ is the root directory - the top of the entire file system hierarchy. All paths start from /. ~ is a shortcut for the current user’s home directory (/home/username on Linux or /Users/username on macOS). cd / goes to root. cd ~ or just cd goes to home directory. ~username = home directory of a specific user. The root user’s home is /root (not /home/root)
What is a process in Unix?
A process is a running instance of a program. Every process has: PID (process ID) + PPID (parent PID) + owner + working directory + environment variables + open file descriptors. Process types: foreground (takes terminal control) + background (runs with & suffix) + daemon (background service - no terminal). Key commands: ps (list processes) + top/htop (real-time) + kill PID (send signal) + jobs (list background jobs)
MEMORY BOOSTER: Unix file system
Inode = file metadata (permissions + owner + size + disk pointers) - NOT filename. Absolute path = starts with / (from root). Relative path = from current dir (. = here - .. = parent - ~ = home). ls -l first char: - (file) + d (dir) + l (symlink) + b/c (devices). Permissions: rwxrwxrwx (owner/group/other). chmod 755 = rwxr-xr-x. Hard link = same inode. Symlink = path pointer (can be broken). Key dirs: /etc (config) + /var (logs) + /home (users) + /tmp (temp)
What are the most important Unix file commands?
ls (list files - ls -la for all with details) + cd (change directory) + pwd (print working dir) + mkdir (make dir - mkdir -p creates parents) + rmdir (remove empty dir) + cp (copy - cp -r for recursive) + mv (move/rename) + rm (remove - rm -r recursive - rm -f force - rm -rf delete everything) + touch (create empty file or update timestamp) + cat (display file) + less/more (paginate) + find (search files)
How do you remove all files in current directory including subdirectories?
rm -r * removes all files and subdirectories recursively in current directory. The * wildcard matches all files/dirs. -r flag = recursive (descends into subdirectories). rm -rf * = recursive + force (no confirmation prompts). WARNING: rm -rf is DESTRUCTIVE and IRREVERSIBLE. Better: rm -rf /path/to/dir/* to be explicit. For safety use find first: find . -type f to preview what will be deleted
What are the most important Unix text processing commands?
cat (concatenate + display files) + grep (search text - grep -r recursive - grep -i case insensitive - grep -v invert) + head (first N lines - head -5 file) + tail (last N lines - tail -f live follow) + cut (extract columns - cut -d: -f1 /etc/passwd) + sort (sort lines - sort -n numeric - sort -r reverse) + uniq (remove duplicates - needs sorted input) + wc (word count - wc -l lines) + tr (translate/delete chars)
What are the most important Unix network commands?
ping (test connectivity) + ssh (secure remote login - ssh user@host) + scp (secure copy - scp file user@host:/path) + curl (HTTP requests - curl -X POST - curl -H header) + wget (download files) + netstat (network connections) + ss (modern netstat) + nmap (port scanner) + ifconfig/ip (network interface config) + dig/nslookup (DNS lookup) + traceroute (trace network path) + telnet (test port connectivity)
What are the most important Unix system commands?
ps (process status - ps aux for all) + top/htop (real-time process monitor) + kill PID (send signal - kill -9 = SIGKILL force) + df (disk filesystem usage - df -h human readable) + du (disk usage - du -sh dir/) + free (memory usage - free -h) + uname -a (kernel + OS info) + whoami (current user) + id (user + group IDs) + uptime (system uptime) + history (command history) + man command (manual pages)
What is the grep command and how do you use it?
grep searches for patterns in files or input. grep ‘pattern’ file + grep -r ‘pattern’ dir/ (recursive) + grep -i ‘pattern’ (case insensitive) + grep -v ‘pattern’ (invert - lines NOT matching) + grep -n ‘pattern’ (show line numbers) + grep -c (count matches) + grep -l (show filenames only) + grep -E ‘pattern’ (extended regex - same as egrep) + grep -o (only matching part). Combine with pipes: ps aux | grep java