Here is my file structure:

- someDirA
  -  folderOne
  -  folderTwo
     - somefile.txt
     - someotherfile.txt

- someDirB
  -  somefolder

What I want 'someDirB' to look like:

- someDirB
  - somefolder
  - folderTwo
    - somefile.txt
    - someotherfile.txt

I just want to copy someDirA's folderTwo(folder and all its contents) into someDirB. Both directories are in separate paths.

  • 1
    You might find cp -a useful, as it adds to -r extra options to preserve file attributes in the copied files. Also cp -ua will copy only updated files if you need to repeat the copy.
    – AFH
    Sep 20 '15 at 20:30

cp -r /path/to/someDirA/folderTwo /path/to/someDirB/

The -r option to cp tells it to recurse on directories, copying its contents.

  • see thats the problem, i the folder i'm copying is not in the same directory as the folder i'm trying to copy too. Both someDirA/folderTwo and someDirB are in separate paths...just like how i posted above..
    – dave
    Sep 20 '15 at 20:12
  • @dave then just specify the paths to the directories... I will update my answer.
    – ethanwu10
    Sep 20 '15 at 20:13

You can use cp to copy files and directories:

cp -r /path/to/someDirA/folderTwo /path/to/someDirB

The -r option is needed when copying directories.

Alternatively, you can use rsync:

rsync -a  /path/to/someDirA/folderTwo /path/to/someDirB
  • If it's a toss-up, give the answer mark to ethanwu10: he was 30 seconds faster than me.
    – John1024
    Sep 20 '15 at 20:15

Simplification for rsync:

rsync -r someDirA/ someDirB

Note there is a trailing slash (/) at the end of the first argument; it is necessary to mean "the contents of someDirA".


rsync -r --exclude 'folderOne' someDirA/ someDirB 
  • The OP only wanted folderTwo copied. This would also copy folderOne.
    – John1024
    Sep 20 '15 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.