Synthird's blog

Copying files and folders in the Linux terminal

Copying files

To copy files, you use the cp command:

cp file folder-destination

The destination folder has a file containing the same name as the file you're trying to copy

If the destination folder has a file containing the same name as the file you're trying to copy, the file in the destination folder will be overwritten.

If you want to avoid that, use the -i flag:

cp -i file folder-destination

You will then be granted a prompt to answer:

cp: overwrite 'folder-destination/file-to-be-overwritten'?

Press y to answer yes, or n to answer no.

Copying folders

To copy folders, you have to use the -r flag:

cp -r folder-to-copy folder-destination