Copy All Subdirectory Contents to New Directory

April 06, 2007

This entry is merely here so I don't have to try and remember where I wrote it down for the next time I need it.

Problem A directory, A, contains many sub-directories, B, C, D, .... Each sub-directory contains one or more files that you want copied to a new directory without the directory hierarchy. Result will be a directory, A1, that contains just files.

Solution The *nix cp command.

cp -r <source_directory>/*/*.filetype .

Copy, recursively for files (little r, not Directories or big R), from the source_directory, searching all folders (/), for all files of a type (/.filetype) to here (.)

Thanks JJ.

Author's profile picture

Mark H. Nichols

I am a husband, cellist, code prole, nerd, technologist, and all around good guy living and working in fly-over country. You should follow me on Twitter.