What does the 'cp' command do?

0179

The cp command in Linux is used to copy files and directories from one location to another.

Basic Syntax:

cp [options] source destination

Common Options:

  • -r: Recursively copy directories and their contents.
  • -i: Prompt before overwriting files.
  • -u: Copy only when the source file is newer than the destination file or when the destination file is missing.

Examples:

  1. Copy a file:

    cp file.txt /path/to/destination/

    This copies file.txt to the specified destination directory.

  2. Copy a directory:

    cp -r /source/directory /path/to/destination/

    This copies the entire directory and its contents.

  3. Copy with prompt:

    cp -i file.txt /path/to/destination/

    This will ask for confirmation before overwriting an existing file.

Let me know if you have more questions about the cp command or anything else!

0 Comments

no data
Be the first to share your comment!