Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Move files from parent directories to subdirectories based on file extension

I have 139 directories that contain a subdirectory and files that need to be moved into the subdirectory. I thought the simplest way to do this would be to use a mv command to recursively move the files based on their file extension of which there are only two. I have something like this:

xxx_03_001
 - xxx_03_001/xxx_03_001.csv
 - xxx_03_001/xxx_03_001.jpg
 - xxx_03_001/submissionDocumentation

xxx_03_002
 - xxx_03_002/xxx_03_002.csv
 - xxx_03_002/xxx_03_002.jpg
 - xxx_03_002/submissionDocumentation

I want:

xxx_03_001
 - xxx_03_001/submissionDocumentation/xxx_03_001.csv
 - xxx_03_001/submissionDocumentation/xxx_03_001.jpg

xxx_03_002
 - xxx_03_002/submissionDocumentation/xxx_03_002.csv
 - xxx_03_002/submissionDocumentation/xxx_03_002.jpg

How can I move these files recursively into the submissionDocumentation subdirectory within each parent directory?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Run this in the top level directory:

for dir in xxx_*; do
    mv "$dir"/*.{csv,jpg} "$dir"/submissionDocumentation/
done
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading