Skip to content Skip to footer

Understanding the cp Command in Bash | by Javascript Jeep🚙💨 | Aug, 2024


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

Copy Command Syntax and Explanation

The basic syntax of the cp command is:

cp [OPTION]... SOURCE... DESTINATION
  • SOURCE: The file or directory you want to copy.
  • DESTINATION: The location where you want to place the copied file or directory.
  • OPTION: Optional flags that modify the behavior of the cp command.

Commonly used options include:

  • -r or -R: Recursively copy directories and their contents.
  • -i: Prompt before overwriting an existing file.
  • -u: Copy only when the SOURCE file is newer than the DESTINATION file or when the DESTINATION file is missing.
  • -v: Verbose mode, which shows the files being copied.
  • -T: Treat the destination as a normal file. This is useful when you don’t want to create a new directory at the destination.
  • -f: Force the copy operation by removing the destination file if it cannot be opened.

Copying Files Example



Source link

Leave a comment

0.0/5