Copy a file and ask before overwriting.
cp -i report.txt ./archive/Copy files. Add -r when copying a directory and its contents.
cp [OPTION]... SOURCE... DESTINATIONCopy a file and ask before overwriting.
cp -i report.txt ./archive/Copy a directory tree while preserving attributes.
cp -a project/ backup/project/| Option / clause | Description |
|---|---|
-a, --archive | Preserve attributes and copy recursively; equivalent to -dR --preserve=all. |
-r, -R, --recursive | Copy directories recursively. |
-i, --interactive | Prompt before overwriting a destination. |
-n, --no-clobber | Do not overwrite an existing destination. |
-u, --update | Copy when the source is newer or destination is missing. |
-p, --preserve=mode,ownership,timestamps | Preserve selected file attributes. |
-v, --verbose | Explain what is being copied. |
Review a command and its target before running it. Commands that alter files, services, accounts, disks, permissions or databases may be difficult to reverse. Test in a safe environment and keep backups.