LinuxTutorial2 min read

How to Copy, Move, and Delete Files on Linux

Master the cp, mv, and rm commands to manage files and directories on Linux, including the most useful flags and how to avoid common mistakes.

Developer terminal on a laptop in low light

The Three Core File Commands

On Linux, three commands handle almost all file management from the terminal: cp (copy), mv (move/rename), and rm (remove). Once you know them well, you will find the terminal faster than any file manager for bulk operations.

cp — Copy Files and Directories

Basic syntax: cp source destination

cp report.txt backup/report.txt     # copy a file
cp -r projects/ backup/projects/    # copy a directory (-r = recursive)
cp -u *.txt /backup/                # copy only files newer than the destination
  • -r — recursive (required for directories)
  • -v — verbose, print each file as it's copied
  • -p — preserve timestamps and permissions
  • -i — interactive, ask before overwriting

mv — Move or Rename

mv moves a file to a new location, or renames it if the destination is in the same directory:

mv old-name.txt new-name.txt        # rename
mv report.txt ~/Documents/          # move to another directory
mv *.log /var/log/archive/          # move multiple files with a glob

Warning: mv overwrites the destination silently. Use -i to get a prompt before overwriting.

rm — Remove Files

rm file.txt                         # delete a file
rm -r old-project/                  # delete a directory and all its contents
rm -rf temp/                        # force delete without prompts (use carefully)
rm -i *.log                         # ask before deleting each file

Important: Linux has no Recycle Bin from the terminal. Deleted files are gone immediately. When in doubt, use rm -i or move files to a temporary folder first.

Working with Directories: mkdir and rmdir

mkdir new-folder                    # create a directory
mkdir -p projects/web/assets        # create nested directories at once
rmdir empty-folder                  # remove an empty directory
rm -r non-empty-folder              # remove a directory with contents

Practical Examples

# Back up config files before editing
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak

# Reorganise downloads
mkdir -p ~/sorted/{images,videos,docs}
mv ~/Downloads/*.jpg ~/sorted/images/
mv ~/Downloads/*.mp4 ~/sorted/videos/
mv ~/Downloads/*.pdf ~/sorted/docs/

Quick Reference

  • cp -r src/ dst/ — copy directory recursively
  • mv file.txt newname.txt — rename a file
  • rm -rf dir/ — delete directory (no undo!)
  • mkdir -p a/b/c — create nested directories