Copying files based on a condition

user2398029

Here's the problem I'm attempting to solve:

  • Let's say I have a directory "A", containing some files as well as some other directories.
  • I want to copy all the files directly under directory A to directory B.
  • I want to recursively copy all the folders inside folder A to folder C.

What is the shortest and less platform-specific way to accomplish this in UNIX/Linux?

Bernhard

Probably something like this

find A -type f -maxdepth 1 -exec cp {} B/ \;

And

find A -type d -maxdepth 1 -mindepth 1 -exec cp -r {} C/ \;

Where -type is a flag, determining the type you're looking for (file or directory), - maxdepth how deep into directory, and -exec for executing a command on the result.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related