cp: Copy — Copy files or directories. cp copies files and folders. cp config.example.php config.php copies a file, and cp -r assets backup/ copies a whole folder with everything inside. By default, cp overwrites the destination without asking. cp -i asks first, and cp -n never overwrites. cp -p keeps the original timestamps and permissions, which matters for backups.
For anything large or remote, rsync is usually the better tool. It only copies what changed, can resume after an interruption, and shows progress. For quick local backups before editing a config file, cp file file.bak is a good habit. It takes a second and makes it easy to restore the original if the change goes wrong.
Use before running or suggesting shell commands with flags, especially destructive or broad ones (-f/--force, -r/-R recursive, -a/--all, -y/--yes, prune, --hard), and when a user asks what a flag means (-v, -q, -n/--dry-run, -h, -o, -p, -t, -u, -w, -x, -c, -i). Explains flags per tool and prefers dry runs and narrow scopes.
Master defensive Bash programming techniques for production-grade scripts. Use when writing robust shell scripts, CI/CD pipelines, or system utilities requiring fault tolerance and safety.