31

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.

user702300
  • 1,211
  • 5
  • 22
  • 32

2 Answers2

47

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 :)

Vadim Landa
  • 2,784
  • 5
  • 23
  • 33
4

For me the main barrier was the /home part. I needed to copy files from a folder in my home that started with the letter 'a' to my current folder, which was not home. So I used:

cp home/tmp/a* ./

the first line worked for me. While I was trying commands like:

cp ~/home/tmp/a* ./

but this didn't work.

Georges
  • 233
  • 4
  • 16
Aadn
  • 93
  • 1
  • 5