Copy, move, and remove

Lesson 13 of 30 · Working with Linux

A copy gives the content another file; moving changes where a name points. Removal takes a name out of a directory. Work in a new empty disposable directory for this sequence:

mkdir drafts archive
printf 'Outline\n' > drafts/outline.txt
cp drafts/outline.txt drafts/review.txt
mv drafts/review.txt drafts/ready.txt
mv drafts/ready.txt archive/
cat drafts/outline.txt
cat archive/ready.txt

Both cat commands print Outline. cp left the original in place; the first mv renamed the copy, and the second put it inside the existing archive directory with its name unchanged. Both source and destination are interpreted relative to the current directory. A destination that already exists can be overwritten; cp -i and mv -i ordinarily prompt before overwriting, but review prompts and do not rely on them as backups. Inspect both paths before acting.

A directory tree can be copied with cp -R drafts drafts-copy when drafts-copy does not exist. If the destination exists, placement differs: the source can be copied inside it. A copy is only a useful backup if it is stored and maintained appropriately; a second file beside the first is vulnerable to the same mistakes.

To remove the disposable copy:

ls -l archive/ready.txt
rm archive/ready.txt
rmdir archive

rm removes the file name without placing it in the desktop trash; do not count on an undo. rmdir removes an empty directory and refuses a nonempty one. rm -r instead descends into a directory and removes its contents too. Before any recursive removal, check pwd, the exact target and its contents, including hidden names; do not use it on an unknown or important path. Avoid wildcards until you understand which names the shell expands. Interactive prompts reduce some mistakes but do not make a wrong target safe.