How to change copy files and directories in linux

How to change copy files and directories in linux

cp name

cp  – copy files and directories

2. cp synopsis

cp [OPTION]... [-T] SOURCE DEST
cp [OPTION]... SOURCE... DIRECTORY
cp [OPTION]... -t DIRECTORY SOURCE... 

3. cp frequently used options

-i, --interactive
       prompt before overwrite
-p     same as --preserve=mode,ownership,timestamps
-R, -r, --recursive
       copy directories recursively
-v, --verbose explain what is being done 

4. cp examples

Copy directory dir2 and its content into directory dir1:

cp -r dir2/ dir1/ 

Copy directory dir2 including its content
Copy all files from dir2 to dir1:

cp dir2/* dir1/ 

Copy all files
Copy file1 from dir1 to dir2 but prompt before overwrite:

cp -i dir1/file1 dir2/ 

Copy all files and prompt before overwrite
Copy file1 from dir1 to dir2 and preserve mode,ownership and timestamps:

cp -p dir1/file1 dir2/ 

copy file and preserve mode,ownership and timestamps

Source taken from http://linuxconfig.org/