1

I have a bunch of files in separate folders, and all of the folders are in one directory.

/var/www/folder1/file1.txt
/var/www/folder1/file2.txt
/var/www/folder1/file3.txt

/var/www/folder2/file4.jpg
/var/www/folder2/file5.jpg
/var/www/folder2/file6.jpg

/var/www/folder3/file7.pdf
/var/www/folder3/file8.doc
/var/www/folder3/file9.gif

I need everything inside of the folders that are inside of /var/www/ to be copied to another directory (say, /var/my-directory/), but not the actual folders. Based on the example above, I need /var/my-directory/` to look as follows:

/var/my-directory/file1.txt
/var/my-directory/file2.txt
/var/my-directory/file3.txt
/var/my-directory/file4.jpg
/var/my-directory/file5.jpg
/var/my-directory/file6.jpg
/var/my-directory/file7.pdf
/var/my-directory/file8.doc
/var/my-directory/file9.gif

I can't seem to figure out the command to do this. I've tried the following:

sudo cp -R /var/www/./. /var/my-directory/

But, that still copies all of the folders.

Is there any way to do what I'm trying to do?

1
  • Simply use cp /var/www/*/file* /var/my-directory/... Commented May 2, 2017 at 16:12

1 Answer 1

3

Use find.

find /var/www/ -type f -exec cp '{}' /var/my-directory/  \;

The trick is -type f that only selects file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.