CS-150 – Introduction to Command Line Programming
Unix Family of Operating Systems
- Unix = modular OS; core written in C; resources treated as files
- Key traits: small tools + pipes, hierarchical file system, shell scripting culture
- Major variants: original AT\&T Unix, ext{Linux} (open-source re-implementation), macOS
Shell & CLI Basics
- Shell = interface between user & kernel; common types: CLI (focus) and GUI (ignored here)
- Popular shells: sh, bash (default on most Linux), zsh, csh, ksh, tcsh
- Prompt symbols: \$ (regular user) , # (root)
- Command format: command\ [arg1]\ …\ [argN]
Bash Essentials
- Bash ⊇ sh; extra features, intuitive for beginners, cross-platform (Linux, macOS, Windows via WSL)
- Command-line editing via readline (arrows, \text{Ctrl-A/E/K/Y}, \text{Tab} completion, history)
Commands, Flags & Help
- Coreutils & built-ins coexist; built-ins (e.g. cd, pwd) executed by shell itself
- Flags modify behaviour: short (-l), long (--recursive); often order-independent but placed before file args
- Documentation: man, info, command\ --help
Directory & File Operations
- Navigation: pwd, cd\ dir, cd\ .., cd (home)
- Directories: mkdir (create), rmdir (remove empty)
- Listing: ls with common flags -a\,-l\,-t\,-R
- Files: touch (create/update timestamp), cp (copy), mv (move/rename), rm (remove)
- Viewing: cat (concatenate), head/tail (\text{-n} lines), less (paging), echo (print)
I/O Redirection & Pipes
- File descriptors: stdin 0, stdout 1, stderr 2
- Redirect stdout: > (overwrite), >> (append)
- Redirect stderr: 2> file
- Redirect stdin: < file
- Pipe: command1\ |\ command2 (stdout → stdin)
Wildcards (Globbing)
- * any string; ? single char; [abc] char class/range; {a,b} alternatives
Permissions & Ownership
- Three subjects: user, group, other; three rights: read r, write w, execute x
- Octal mapping: rwx=7, rw-=6, r-x=5, r--=4, etc.
- Change permissions: chmod\ 774\ file (numeric) or chmod\ +x\ file (symbolic)
- Change owner/group: chown\ user{:group}\ file
Shell Scripting Basics
- Script = text file with sequential shell commands; extension .sh (convention)
- Shebang #!\/bin\/bash → selects interpreter
- Creation: any editor (e.g. nano), redirection, etc.
- Execution: source\ script.sh (current shell) or ./script.sh (needs chmod\ +x)
Quick Reference Resources
- learnshell.org – interactive practice
- guide.bash.academy – conceptual deep-dive
- linuxconfig.org & ryanstutorials.net – beginner-friendly tutorials