CP COMMAND

cp command in Linux/Unix

cp is a Linux shell command to copy files and directories.

  • cp syntax
  • cp options
  • cp examples
  • cp code generator

cp command syntax

Copy from source to dest

$ cp [optionssource dest

cp command options

cp command main options:

optiondescription
cp -aarchive files
cp -fforce copy by removing the destination file if needed
cp -iinteractive - ask before overwrite
cp -llink files instead of copy
cp -Lfollow symbolic links
cp -nno file overwrite
cp -Rrecursive copy (including hidden files)
cp -uupdate - copy when source is newer than dest
cp -vverbose - print informative messages

cp command examples

Copy single file main.c to destination directory bak:

$ cp main.c bak

 

Copy 2 files main.c and def.h to destination absolute path directory /home/usr/rapid/ :

$ cp main.c def.h /home/usr/rapid/

 

Copy all C files in current directory to subdirectory bak :

$ cp *.c bak

 

Copy directory src to absolute path directory /home/usr/rapid/ :

$ cp src /home/usr/rapid/

 

Copy all files and directories in dev recursively to subdirectory bak:

$ cp -R dev bak

 

Force file copy:

$ cp -f test.c bak

 

Interactive prompt before file overwrite:

$ cp -i test.c bak
cp: overwrite 'bak/test.c'? y

 

Update all files in current directory - copy only newer files to destination directory bak:

$ cp -u * bak

cp code generator

Select cp options and press the Generate Code button:

Previous Post Next Post