Backup file

2 snippets in Bash & Linux

Also written as backup files

SHBash & Linux

Copy Files & Directories

SH · Navigation & Files
Syntax
cp [options] source destination
Example
cp config.yml config.yml.bak
cp -r templates/ /opt/app/templates/
cp -i report.csv ~/Desktop/

Note -r is required for directories (recursive copy). -i prompts before overwriting. Without -i, cp silently overwrites the destination. Use -a to preserve permissions, timestamps, and symlinks.

Create a Tar Archive

SH · Archives & Compression
Syntax
tar -cf archive.tar files...
tar -czf archive.tar.gz files...
Example
tar -czf backup_20260404.tar.gz /opt/app/data/ /opt/app/config/
tar -cjf source.tar.bz2 --exclude='.git' --exclude='node_modules' project/

Note -c creates, -z compresses with gzip, -j with bzip2, -J with xz. -f must be followed by the archive name. --exclude omits patterns. Always put -f last among the single-letter flags or use the long form to avoid mistakes.

Frequently asked questions

How does Bash & Linux handle backup file?
Bash & Linux covers this with 2 copy-ready snippets on this page. The "Copy Files & Directories" snippet in Bash & Linux uses `cp [options] source destination`.
Which command does the Bash & Linux example use?
The "Copy Files & Directories" snippet uses `cp [options] source destination`, from the Navigation & Files section of the Bash & Linux cheat sheet.
What other Bash & Linux snippets are shown for "backup file"?
Besides "Copy Files & Directories", this page also shows "Create a Tar Archive".
Is there anything to watch out for?
Yes. For "Copy Files & Directories": -r is required for directories (recursive copy). -i prompts before overwriting. Without -i, cp silently overwrites the destination. Use -a to preserve permissions, timestamps, and symlinks.