
Part two in the Linux Command Series
Published on June 10, 2026 by Mike Chilson
Commands Terminal Bash Linux Tutorial
4 min READ
The cp, rm, and mv commands form the essential “File Trinity” for managing files/directories in Linux and Unix-like systems.
cp (copy) duplicates files and directories. rm (remove) deletes them. mv (move) relocates or renames them.
Mastering these three commands is critical for efficient and safe file management in the terminal. This tutorial covers basic usage, common options, advanced techniques, and important safety.
Copying Files and Directories with cp
Copy a Single File
cp source.txt destination.txt
This creates an exact copy of source.txt as destination.txt.
Copy a File to a Directory
cp document.pdf /home/user/Documents/
The file keeps its original name in the target directory.
Copy Multiple Files
cp file1.txt file2.txt file3.txt /target/directory/
cp *.txt /target/directory/
Copy a Directory Recursively (Use the -r or -R flag for directories)
cp -r projects/ /backup/projects/
Removing Files and Directories with rm
Delete a Single File
rm unwanted.txt
Delete Multiple Files
rm file1.log file2.log
rm *.log
rm file[1-5].log
Delete a Directory and All Contents
rm -r old_project/
Warning: rm is permanent—there is no recycle bin.
Moving or Renaming with mv
Move a File to Another Directory
mv report.pdf /home/user/Archives/
Rename a File
mv old_name.txt new_name.txt
Move and Rename in One Step
mv data.csv /archive/final_report_2026.csv
Move Multiple Items
mv file1.txt file2.txt archive/
mv *.txt archive/
mv file[1-2].txt archive/
For the cp command
-r / -R Recursive: copy directories and contents cp -r src/ dest/
-i Interactive: prompt before overwrite cp -i file.txt existing.txt
-v Verbose: show what is being copied cp -v *.jpg images/
-u Update: copy only if source is newer cp -u *.txt backup/
-p Preserve: keep permissions, timestamps, etc. cp -p important.doc ~/secure/
-a Archive: like -p -r -d for backups cp -a /etc/configs/ ~/backup/
For rm (Remove)
-i Interactive: prompt for each file rm -i *.tmp
-I Interactive: prompt once for multiple files (safer than -f) rm -I *.bak
-f Force: no prompts, ignore non-existent files rm -f temp.log
-r / -R Recursive: delete directories and contents rm -r folder/
-v Verbose: show what is being removed rm -rv old_dir/
For mv (Move/Rename)
-i Interactive: prompt before overwrite mv -i file.txt existing.txt
-v Verbose: show what is being moved mv -v *.png images/
-u Update: move only if source is newer mv -u newdata/ archive/
-b Backup: creates a backup of the existing file in the destination if the same file name already exists mv -b config.conf config.conf.bak
Copy with Wildcards (All Three Commands Support These)
Copy all JPEGs
cp *.jpg /pictures/
Remove all temporary files
rm *.tmp
Move all pdf files to another directory
mv report_*.pdf /final_reports/
Safe Recursive Operations
Copy entire home directory structure (removing ownernship)
cp -a --no-preserve=ownership /home/user/ /backup/
Remove a directory and all its contents
rm -rf testdata/
Careful! Make sure this is what you want to do!
Move and Rename in Bulk
You can combine mv with shell features, Rename all .txt to .md
for file in *.txt; do mv "$file" "${file%.txt}.md"; done
Copy Only Newer Files Across Systems
cp -u -v /local/project/* user@remote:/remote/project/
Use scp or rsync for remote, but cp locally
Always use -i when unsure, especially with rm and mv.
Test with echo first: echo rm -rf *.tmp to preview what will be deleted. Create aliases for safety (add to ~/.bashrc):
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
Use rsync for complex copies, more powerful than cp for large directories and remote transfers.
Check before destructive actions: ls first, then act.
Permissions matter. You may need sudo for system files, but be extremely careful.
Recovering deleted files is difficult. Use backups or tools like testdisk/photorec only as last resort.
Golden Rule: Never run rm -rf / or similar without understanding the consequences.
The cp, rm, and mv commands are the foundation of Linux file management. Once you master their basic syntax, options, and safe practices, you’ll navigate and organize your filesystem with confidence and speed. Practice in a safe directory first. Combine these commands with ls, pipes (), and shell loops for powerful automation.
More details are available in the man pages:
man cp
man rm
man mv
Stay tuned for more tutorials.