Empowering a brighter world through superior education is our commitment.

Online Calculators & Tools

cp command in Linux/Unix

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

cp command syntax

Copy from source to dest

$ cp [options] source 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/calc/ :

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

 

Copy all C files in current directory to subdirectory bak :

$ cp *.c bak

 

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

$ cp src /home/usr/calc/

 

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:

Options
Force copy (-f)
Interactive - ask before overwrite (-i)
Link files (-l)
Follow symbolic links (-L)
No overwrite (-n)
Recursive directory tree copy (-R)
Update newer files (-u)
Verbose messages (-v)
 
Files / folders
Source files / folders:
Destination folder / file:
 
Output redirection
 
 

Click on textbox to select code, then copy and paste it into terminal: