Linux command: cp
Make a second copy of a file
A file is information saved under a name. To make a second copy while keeping the original where it is, use the Linux cp command. The source is what you copy; the destination is where the new copy goes. For example, cp ./notes.txt ./notes-copy.txt makes a copy beside the original. Check both paths first: a command can succeed and still place a file somewhere you did not expect.
For a small backup, create a folder and copy a file into it, then copy a whole folder tree:
mkdir -p ./backup
cp -i -- ./app.conf ./backup/app.conf
cp -a -- ./site-config ./site-config.backup
mkdir -p creates the backup folder if needed. The first cp asks before replacing an existing destination because of -i. The last command makes an archive-style copy of a directory tree. In GNU Coreutils, -a copies directories recursively, preserves symbolic links, and asks to preserve file attributes such as permissions and timestamps.
Choose where and what to copy
The basic form is cp SOURCE DEST. If DEST names a directory, cp puts the source inside it using the source's basename, the last part of its path. If DEST names a file, cp creates or replaces that file. Multiple source paths require a directory destination. GNU cp replaces an existing destination by default; -i asks before doing so. Put -- before paths that may begin with a hyphen, as in cp -- ./-draft ./draft-copy, so the command treats them as names rather than options. Quote paths with spaces to keep each path as one argument to the command.
Use -R or -r to copy a directory tree. Symbolic links are path references that point to another file or directory. GNU cp has -H, -L, and -P to choose how it follows source links. Recursive copies use -P by default and preserve links found inside the tree. For a command-line source that is itself a link, GNU cp normally follows it for a non-recursive copy. -a also selects link and attribute behavior; check the manual when those details matter. Inspect links with ls -l or find.
Check the result
Before a large copy, run pwd to see the current directory and inspect the exact source and destination. Review wildcards and variables, since they can expand to paths you did not intend. For one regular file, cmp SOURCE DEST checks whether contents match. For a directory tree, compare relevant files or use a recursive diff where available. Check ownership, group, permissions, timestamps, and links separately when they matter.
A copy may stop partway through if the destination is read-only, permissions are missing, the source cannot be read, or the filesystem is full. Read the status and error messages, then check for partial results before treating a tree as complete. GNU-specific options may not exist in another Unix implementation of cp; use the local manual when portability matters.







