cp is a Linux shell command to copy files and directories.
Copy from source to dest
$ cp [options] source dest
cp command main options:
option | description |
---|---|
cp -a | archive files |
cp -f | force copy by removing the destination file if needed |
cp -i | interactive - ask before overwrite |
cp -l | link files instead of copy |
cp -L | follow symbolic links |
cp -n | no file overwrite |
cp -R | recursive copy (including hidden files) |
cp -u | update - copy when source is newer than dest |
cp -v | verbose - print informative messages |
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
Select cp options and press the Generate Code button: