Linux cp command to copy a folder to current directory

cp
user702300 picture user702300 · Apr 14, 2015 · Viewed 86.8k times · Source

I am wondering if there is an identical command for copying a folder to current directory like it did using the old MS-DOS. Let's say my current directory location is:

/var/www/

I have folders and files at:

/home/hope/subfolder/docs/
/home/hope/subfolder/images/
/home/hope/subfolder/.config
/home/hope/subfolder/readme.txt

I know that the following command:

cp -rT /home/hope/subfolder .

will copy all the files (even dot hidden files) and folders within the "subfolder" folder to the current directory, so the result will be:

/var/www/docs/
/var/www/images/
/var/www/.config
/var/www/readme.txt

Looks like the command to that to copy the source folder to the current location is:

cp -rT /home/hope/subfolder ./subfolder

although this is fine, I find it that sometimes I will make mistakes for complicated folder names for the destination, so is there a way to use a command like:

cp -rT /home/hope/subfolder .

or even like this

cp -rT /home/hope/subfolder /var/www/.

to have the following result:

/var/www/subfolder/docs/
/var/www/subfolder/images/
/var/www/subfolder/.config
/var/www/subfolder/readme.txt

Thank you.

Answer

Vadim Landa picture Vadim Landa · Apr 14, 2015

Just omit the -T parameter, as that's what prevents the command from working properly:

cp -r /home/hope/subfolder .

The -T parameter treats the target argument as a file, so no copying will be performed at all if that is actually a directory.

A friendly reminder: virtually all Unix commands have a --help command line argument that is worth trying out in case of a trouble :)