Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Flatten a directory structure ' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Flatten a directory structure
Authored by: lsequeir on Mar 05, '13 05:45:03AM

Actually, the find command can also execute a command on each file it finds - that's what the -exec option is for.

Also, I think there was a "." missing in the original hint (the first argument to find is usually the directory where the search starts; after doing cd then you would want to start at the current directory).

Here is a shorter version (and, to my mind, clearer). Just replace (or set) $ROOT_DIRECTORY and $FLAT_DIRECTORY and run:


find $ROOT_DIRECTORY -type f -exec cp -n {} $FLAT_DIRECTORY \;


(the two braces {} are find's convention for the current found file; the semicolon ends the exec command and must be escaped to prevent the shell from interpreting it)

---
Luís



[ Reply to This | # ]