Frequently Asked Question

How do cp, mv and rm actually behave?

cp copies one file or directory to another. By default it duplicates the byte contents and gives the new file fresh permissions and timestamps. cp -r recurses into directories, and cp -a ("archive mode") preserves owners, permissions, timestamps, and symlinks, what you want when copying a tree you intend to keep identical. mv renames or moves. Within a single filesystem it is near-instant because it only rewrites directory entries; across filesystems the kernel cannot simply re-point an inode, so mv quietly turns into copy-then-delete.

rm unlinks. It removes the directory entry and decrements the link count on the inode; if the count reaches zero and no process still has the file open, the kernel releases the data blocks. There is no Recycle Bin, no undelete, and rm -rf will cheerfully walk a tree obliterating everything as it goes. The combination rm -rf $VAR/` with `$VAR accidentally empty has ended careers. Always pause before typing it, and consider aliasing rm to rm -i on interactive shells, or using a tool like trash-cli that moves files into a recoverable location.

Further reading and video