Copying and Renaming — cp and mv
Before she changes her harvest spreadsheet, Asha wants a spare copy. Later she wants to rename the whole plots folder to beds. Copying and renaming look alike on the command line, but they leave very different results behind.
The rule
cp leaves the original; mv takes it away.
cp makes a new, independent copy. The original stays exactly where it was:
$ cd ~/garden
$ cp harvest.csv harvest-backup.csv # copy under a new name
$ cp harvest.csv /tmp/ # copy into another folder
$ cp -r plots plots-2025 # copy a directory: needs -rRenaming in Linux is simply moving to a new name with mv (you met mv in section 1). There is no separate rename command in the basic toolkit:
$ mv plots beds # rename a folder
$ mv harvest.csv harvest-2026.csvOptions worth knowing for cp:
| Option | Does |
|---|---|
-r |
copy directories and everything inside them |
-i |
ask before overwriting an existing file |
-n |
never overwrite |
-p |
keep the original's timestamps and permissions |
-a |
archive mode: recursive and keep everything, which is best for backups |
-v |
print each file as it's copied |
Like mv, cp overwrites an existing destination without asking unless you add -i or -n.
To rename many files at once, a short loop does the job. Here every .txt in the folder becomes .md:
$ for f in *.txt; do mv "$f" "${f%.txt}.md"; done${f%.txt} means "the value of f with .txt cut off the end". Some systems also include a rename tool, but its options differ between distributions, so check man rename before using it.