{
    "mode": "man",
    "parameter": "cp",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/cp/1/json",
    "generated": "2026-09-18T20:58:55Z",
    "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": "--debug",
                    "content": "explain how a file is copied.  Implies -v\n",
                    "long": "--debug"
                },
                {
                    "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 and do not fail (overrides a -u or previous -i op‐\ntion). See also --update; equivalent to --update=none.\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\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\n--update[=UPDATE]\ncontrol which existing files are updated; UPDATE={all,none,older(default)}.  See below\n",
                    "flag": "-T",
                    "long": "--no-target-directory"
                },
                {
                    "name": "-u      --update",
                    "content": "",
                    "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\nATTRLIST is a comma-separated list of attributes. Attributes are 'mode' for permissions (in‐\ncluding any ACL and xattr permissions), 'ownership' for user and group, 'timestamps' for file\ntimestamps,  'links' for hard links, 'context' for security context, 'xattr' for extended at‐\ntributes, and 'all' for all attributes.\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\nUPDATE  controls  which existing files in the destination are replaced.  'all' is the default\noperation when an --update option is not specified, and results in all existing files in  the\ndestination  being  replaced.  'none' is similar to the --no-clobber option, in that no files\nin the destination are replaced, but also skipped files do not induce a failure.  'older'  is\nthe  default  operation  when  --update  is specified, and results in files being replaced if\nthey're older than the corresponding source file.\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  ©  2023 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": "install(1)\n\nFull documentation <https://www.gnu.org/software/coreutils/cp>\nor available locally via: info '(coreutils) cp invocation'\n\nGNU coreutils 9.4                           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": "",
            "long": "--debug",
            "arg": null,
            "description": "explain how a file is copied. Implies -v"
        },
        {
            "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 and do not fail (overrides a -u or previous -i op‐ tion). See also --update; equivalent to --update=none."
        },
        {
            "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 --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 --update[=UPDATE] control which existing files are updated; UPDATE={all,none,older(default)}. See below"
        },
        {
            "flag": "-u",
            "long": "--update",
            "arg": null,
            "description": ""
        },
        {
            "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 ATTRLIST is a comma-separated list of attributes. Attributes are 'mode' for permissions (in‐ cluding any ACL and xattr permissions), 'ownership' for user and group, 'timestamps' for file timestamps, 'links' for hard links, 'context' for security context, 'xattr' for extended at‐ tributes, and 'all' for all attributes. 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. UPDATE controls which existing files in the destination are replaced. 'all' is the default operation when an --update option is not specified, and results in all existing files in the destination being replaced. 'none' is similar to the --no-clobber option, in that no files in the destination are replaced, but also skipped files do not induce a failure. 'older' is the default operation when --update is specified, and results in files being replaced if they're older than the corresponding source file. 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": [
        {
            "name": "install",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/install/1/json"
        }
    ],
    "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}}"
            }
        ]
    }
}