Linux cp Guide - ryzendew/Linux-Tips-and-Tricks GitHub Wiki
Linux cp Guide
Complete beginner-friendly guide to cp on Linux, covering Arch Linux, CachyOS, and other distributions including copying files, directories, and backup operations.
Table of Contents
Understanding cp
What is cp?
cp (copy) copies files and directories.
Uses:
- Copy files: Duplicate files
- Backup: Create backups
- Duplicate: Make copies
- File management: Manage files
Why it matters:
- Backup: Create file backups
- Duplication: Copy files
- Organization: Organize files
cp Basics
Copy File
Basic usage:
# Copy file
cp source.txt destination.txt
# Copy to directory
cp file.txt /path/to/directory/
Multiple Files
Copy several:
# Copy multiple files
cp file1.txt file2.txt file3.txt /destination/
# All copied to destination
Copying Files
Preserve Attributes
Keep properties:
# Preserve attributes
cp -p source.txt dest.txt
# Keeps:
# - Permissions
# - Timestamps
# - Ownership
Interactive Mode
Confirm overwrite:
# Interactive mode
cp -i source.txt dest.txt
# Asks before overwriting
Copying Directories
Recursive Copy
Copy directory:
# Copy directory
cp -r source/ destination/
# Recursive copy
Preserve Structure
Keep structure:
# Preserve all
cp -a source/ destination/
# -a = archive mode
# Preserves everything
Troubleshooting
Permission Denied
Fix permissions:
# Check permissions
ls -l source.txt
# Use sudo if needed
sudo cp source.txt /destination/
Summary
This guide covered cp usage, file/directory copying, and backup operations for Arch Linux, CachyOS, and other distributions.
Next Steps
- mv Guide - Move/rename files
- rsync Guide - Advanced copying
- Backup and Restore - Backup strategies
- cp Documentation:
man cp
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.