Deleting, Moving & Copying
Managing your files is a core skill in Linux. Unlike a graphical user interface, there is no "Trash Can" when you delete a file from the terminal—once it's gone, it's gone!
1. cp (Copy)
The cp command copies files or directories from a source to a destination.
Bash
# Copy a file to a new name cp notes.txt backup.txt # Copy a file to another directory cp notes.txt Documents/ # Copy an entire directory (requires -r for recursive) cp -r MyFolder MyFolder_Backup
2. mv (Move and Rename)
The mv command is used for both moving files and renaming them.
Bash
# Rename a file mv old_name.txt new_name.txt # Move a file to a different directory mv new_name.txt Documents/ # Move and rename at the same time mv info.txt Archive/old_info.txt
3. rm (Remove)
The rm command deletes files and directories.
Bash
# Delete a single file rm unwanted.txt # Delete a directory and all its contents (DANGEROUS!) rm -r TemporaryFolder
Safety First
Because there is no "undo" button, you can use the -i (interactive) flag to have Linux ask for confirmation before doing anything.
Bash
rm -i important_file.txt