Copy files from one directory into an existing directory

David Chang picture David Chang · Sep 4, 2010 · Viewed 320.2k times · Source

In bash I need to do this:

  1. take all files in a directory

  2. copy them into an existing directory

How do I do this? I tried cp -r t1 t2 (both t1 and t2 are existing directories, t1 has files in it) but it created a directory called t1 inside t2, I don't want that, I need the files in t1 to go directly inside t2. How do I do this?

Answer

Nick picture Nick · Jan 10, 2011

What you want is:

cp -R t1/. t2/

The dot at the end tells it to copy the contents of the current directory, not the directory itself. This method also includes hidden files and folders.