{
    "mode": "man",
    "parameter": "CP",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/CP/1/json",
    "generated": "2026-06-10T15:25:48Z",
    "synopsis": "cp [OPTION]... [-T] SOURCE DEST\ncp [OPTION]... SOURCE... DIRECTORY\ncp [OPTION]... -t DIRECTORY SOURCE...",
    "sections": {
        "NAME": {
            "content": "cp - copy files and directories\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "cp [OPTION]... [-T] SOURCE DEST\ncp [OPTION]... SOURCE... DIRECTORY\ncp [OPTION]... -t DIRECTORY SOURCE...\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n\nMandatory arguments to long options are mandatory for short options too.\n",
            "subsections": [
                {
                    "name": "-a --archive",
                    "content": "same as -dR --preserve=all\n",
                    "flag": "-a",
                    "long": "--archive"
                },
                {
                    "name": "--attributes-only",
                    "content": "don't copy the file data, just the attributes\n\n--backup[=CONTROL]\nmake a backup of each existing destination file\n",
                    "long": "--attributes-only"
                },
                {
                    "name": "-b --backup",
                    "content": "",
                    "flag": "-b",
                    "long": "--backup"
                },
                {
                    "name": "--copy-contents",
                    "content": "copy contents of special files when recursive\n",
                    "long": "--copy-contents"
                },
                {
                    "name": "-d --no-dereference --preserve",
                    "content": "",
                    "flag": "-d",
                    "long": "--preserve"
                },
                {
                    "name": "-f --force",
                    "content": "if an existing destination file cannot be opened, remove it and try again (this option\nis ignored when the -n option is also used)\n",
                    "flag": "-f",
                    "long": "--force"
                },
                {
                    "name": "-i --interactive",
                    "content": "prompt before overwrite (overrides a previous -n option)\n",
                    "flag": "-i",
                    "long": "--interactive"
                },
                {
                    "name": "-H",
                    "content": "",
                    "flag": "-H"
                },
                {
                    "name": "-l --link",
                    "content": "hard link files instead of copying\n",
                    "flag": "-l",
                    "long": "--link"
                },
                {
                    "name": "-L --dereference",
                    "content": "always follow symbolic links in SOURCE\n",
                    "flag": "-L",
                    "long": "--dereference"
                },
                {
                    "name": "-n --no-clobber",
                    "content": "do not overwrite an existing file (overrides a previous -i option)\n",
                    "flag": "-n",
                    "long": "--no-clobber"
                },
                {
                    "name": "-P --no-dereference",
                    "content": "never follow symbolic links in SOURCE\n",
                    "flag": "-P",
                    "long": "--no-dereference"
                },
                {
                    "name": "-p --preserve",
                    "content": "--preserve[=ATTRLIST]\npreserve the specified attributes (default:  mode,ownership,timestamps),  if  possible\nadditional attributes: context, links, xattr, all\n\n--no-preserve=ATTRLIST\ndon't preserve the specified attributes\n",
                    "flag": "-p",
                    "long": "--preserve"
                },
                {
                    "name": "--parents",
                    "content": "use full source file name under DIRECTORY\n",
                    "long": "--parents"
                },
                {
                    "name": "-R -r --recursive",
                    "content": "copy directories recursively\n\n--reflink[=WHEN]\ncontrol clone/CoW copies. See below\n",
                    "flag": "-r",
                    "long": "--recursive"
                },
                {
                    "name": "--remove-destination",
                    "content": "remove  each  existing  destination  file  before attempting to open it (contrast with\n--force)\n\n--sparse=WHEN\ncontrol creation of sparse files. See below\n",
                    "long": "--remove-destination"
                },
                {
                    "name": "--strip-trailing-slashes",
                    "content": "remove any trailing slashes from each SOURCE argument\n",
                    "long": "--strip-trailing-slashes"
                },
                {
                    "name": "-s --symbolic-link",
                    "content": "make symbolic links instead of copying\n",
                    "flag": "-s",
                    "long": "--symbolic-link"
                },
                {
                    "name": "-S --suffix",
                    "content": "override the usual backup suffix\n",
                    "flag": "-S",
                    "long": "--suffix"
                },
                {
                    "name": "-t --target-directory",
                    "content": "copy all SOURCE arguments into DIRECTORY\n",
                    "flag": "-t",
                    "long": "--target-directory"
                },
                {
                    "name": "-T --no-target-directory",
                    "content": "treat DEST as a normal file\n",
                    "flag": "-T",
                    "long": "--no-target-directory"
                },
                {
                    "name": "-u --update",
                    "content": "copy only when the SOURCE file is newer than the destination file or when the destina‐\ntion file is missing\n",
                    "flag": "-u",
                    "long": "--update"
                },
                {
                    "name": "-v --verbose",
                    "content": "explain what is being done\n",
                    "flag": "-v",
                    "long": "--verbose"
                },
                {
                    "name": "-x --one-file-system",
                    "content": "stay on this file system\n",
                    "flag": "-x",
                    "long": "--one-file-system"
                },
                {
                    "name": "-Z",
                    "content": "--context[=CTX]\nlike -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX\n\n--help display this help and exit\n",
                    "flag": "-Z"
                },
                {
                    "name": "--version",
                    "content": "output version information and exit\n\nBy  default, sparse SOURCE files are detected by a crude heuristic and the corresponding DEST\nfile is made sparse as well.  That  is  the  behavior  selected  by  --sparse=auto.   Specify\n--sparse=always  to create a sparse DEST file whenever the SOURCE file contains a long enough\nsequence of zero bytes.  Use --sparse=never to inhibit creation of sparse files.\n\nWhen --reflink[=always] is specified, perform a lightweight copy, where the data  blocks  are\ncopied  only  when modified.  If this is not possible the copy fails, or if --reflink=auto is\nspecified, fall back to a standard copy.  Use --reflink=never to ensure a  standard  copy  is\nperformed.\n\nThe backup suffix is '~', unless set with --suffix or SIMPLEBACKUPSUFFIX.  The version con‐\ntrol method may be selected via the --backup option or through the  VERSIONCONTROL  environ‐\nment variable.  Here are the values:\n\nnone, off\nnever make backups (even if --backup is given)\n\nnumbered, t\nmake numbered backups\n\nexisting, nil\nnumbered if numbered backups exist, simple otherwise\n\nsimple, never\nalways make simple backups\n\nAs  a  special  case, cp makes a backup of SOURCE when the force and backup options are given\nand SOURCE and DEST are the same name for an existing, regular file.\n",
                    "long": "--version"
                }
            ]
        },
        "AUTHOR": {
            "content": "Written by Torbjorn Granlund, David MacKenzie, and Jim Meyering.\n",
            "subsections": []
        },
        "REPORTING BUGS": {
            "content": "GNU coreutils online help: <https://www.gnu.org/software/coreutils/>\nReport any translation bugs to <https://translationproject.org/team/>\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright © 2020 Free Software Foundation, Inc.  License GPLv3+: GNU GPL version 3  or  later\n<https://gnu.org/licenses/gpl.html>.\nThis  is free software: you are free to change and redistribute it.  There is NO WARRANTY, to\nthe extent permitted by law.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Full documentation <https://www.gnu.org/software/coreutils/cp>\nor available locally via: info '(coreutils) cp invocation'\n\n\n\nGNU coreutils 8.32                          January 2026                                       CP(1)",
            "subsections": []
        }
    },
    "summary": "cp - copy files and directories",
    "flags": [
        {
            "flag": "-a",
            "long": "--archive",
            "arg": null,
            "description": "same as -dR --preserve=all"
        },
        {
            "flag": "",
            "long": "--attributes-only",
            "arg": null,
            "description": "don't copy the file data, just the attributes --backup[=CONTROL] make a backup of each existing destination file"
        },
        {
            "flag": "-b",
            "long": "--backup",
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--copy-contents",
            "arg": null,
            "description": "copy contents of special files when recursive"
        },
        {
            "flag": "-d",
            "long": "--preserve",
            "arg": null,
            "description": ""
        },
        {
            "flag": "-f",
            "long": "--force",
            "arg": null,
            "description": "if an existing destination file cannot be opened, remove it and try again (this option is ignored when the -n option is also used)"
        },
        {
            "flag": "-i",
            "long": "--interactive",
            "arg": null,
            "description": "prompt before overwrite (overrides a previous -n option)"
        },
        {
            "flag": "-H",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "-l",
            "long": "--link",
            "arg": null,
            "description": "hard link files instead of copying"
        },
        {
            "flag": "-L",
            "long": "--dereference",
            "arg": null,
            "description": "always follow symbolic links in SOURCE"
        },
        {
            "flag": "-n",
            "long": "--no-clobber",
            "arg": null,
            "description": "do not overwrite an existing file (overrides a previous -i option)"
        },
        {
            "flag": "-P",
            "long": "--no-dereference",
            "arg": null,
            "description": "never follow symbolic links in SOURCE"
        },
        {
            "flag": "-p",
            "long": "--preserve",
            "arg": null,
            "description": "--preserve[=ATTRLIST] preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes: context, links, xattr, all --no-preserve=ATTRLIST don't preserve the specified attributes"
        },
        {
            "flag": "",
            "long": "--parents",
            "arg": null,
            "description": "use full source file name under DIRECTORY"
        },
        {
            "flag": "-r",
            "long": "--recursive",
            "arg": null,
            "description": "copy directories recursively --reflink[=WHEN] control clone/CoW copies. See below"
        },
        {
            "flag": "",
            "long": "--remove-destination",
            "arg": null,
            "description": "remove each existing destination file before attempting to open it (contrast with --force) --sparse=WHEN control creation of sparse files. See below"
        },
        {
            "flag": "",
            "long": "--strip-trailing-slashes",
            "arg": null,
            "description": "remove any trailing slashes from each SOURCE argument"
        },
        {
            "flag": "-s",
            "long": "--symbolic-link",
            "arg": null,
            "description": "make symbolic links instead of copying"
        },
        {
            "flag": "-S",
            "long": "--suffix",
            "arg": null,
            "description": "override the usual backup suffix"
        },
        {
            "flag": "-t",
            "long": "--target-directory",
            "arg": null,
            "description": "copy all SOURCE arguments into DIRECTORY"
        },
        {
            "flag": "-T",
            "long": "--no-target-directory",
            "arg": null,
            "description": "treat DEST as a normal file"
        },
        {
            "flag": "-u",
            "long": "--update",
            "arg": null,
            "description": "copy only when the SOURCE file is newer than the destination file or when the destina‐ tion file is missing"
        },
        {
            "flag": "-v",
            "long": "--verbose",
            "arg": null,
            "description": "explain what is being done"
        },
        {
            "flag": "-x",
            "long": "--one-file-system",
            "arg": null,
            "description": "stay on this file system"
        },
        {
            "flag": "-Z",
            "long": null,
            "arg": null,
            "description": "--context[=CTX] like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX --help display this help and exit"
        },
        {
            "flag": "",
            "long": "--version",
            "arg": null,
            "description": "output version information and exit By default, sparse SOURCE files are detected by a crude heuristic and the corresponding DEST file is made sparse as well. That is the behavior selected by --sparse=auto. Specify --sparse=always to create a sparse DEST file whenever the SOURCE file contains a long enough sequence of zero bytes. Use --sparse=never to inhibit creation of sparse files. When --reflink[=always] is specified, perform a lightweight copy, where the data blocks are copied only when modified. If this is not possible the copy fails, or if --reflink=auto is specified, fall back to a standard copy. Use --reflink=never to ensure a standard copy is performed. The backup suffix is '~', unless set with --suffix or SIMPLEBACKUPSUFFIX. The version con‐ trol method may be selected via the --backup option or through the VERSIONCONTROL environ‐ ment variable. Here are the values: none, off never make backups (even if --backup is given) numbered, t make numbered backups existing, nil numbered if numbered backups exist, simple otherwise simple, never always make simple backups As a special case, cp makes a backup of SOURCE when the force and backup options are given and SOURCE and DEST are the same name for an existing, regular file."
        }
    ],
    "examples": [],
    "see_also": [],
    "tldr": {
        "source": "official",
        "description": "Copy files and directories.",
        "examples": [
            {
                "description": "Copy a file to another location",
                "command": "cp {{path/to/source_file}} {{path/to/target_file}}"
            },
            {
                "description": "Copy a file into another directory, keeping the filename",
                "command": "cp {{path/to/source_file}} {{path/to/target_parent_directory}}"
            },
            {
                "description": "Recursively copy a directory's contents to another location (if the destination exists, the directory is copied inside it)",
                "command": "cp {{-r|--recursive}} {{path/to/source_directory}} {{path/to/target_directory}}"
            },
            {
                "description": "Copy a directory recursively, in verbose mode (shows files as they are copied)",
                "command": "cp {{-vr|--verbose --recursive}} {{path/to/source_directory}} {{path/to/target_directory}}"
            },
            {
                "description": "Copy multiple files at once to a directory",
                "command": "cp {{-t|--target-directory}} {{path/to/destination_directory}} {{path/to/file1 path/to/file2 ...}}"
            },
            {
                "description": "Copy all files with a specific extension to another location, in interactive mode (prompts user before overwriting)",
                "command": "cp {{-i|--interactive}} {{*.ext}} {{path/to/target_directory}}"
            },
            {
                "description": "Follow symbolic links before copying",
                "command": "cp {{-L|--dereference}} {{link}} {{path/to/target_directory}}"
            },
            {
                "description": "Use the full path of source files, creating any missing intermediate directories when copying",
                "command": "cp --parents {{source/path/to/file}} {{path/to/target_file}}"
            }
        ]
    }
}