Reputation: 21
I want to create a loop in Linux script that will go thru the folders in one directory and will copy photos to one folder and will overwrite photos that have the same name. Can anyone point me in the write direction?
Upvotes: 2
Views: 116
Reputation: 11703
Actually, you need not to loop through folders for finding photos using script, find
command will do that job for you.
Try using find
with xargs
and cp
find source_dir -type f -iname '*.jpg' -print0 | xargs -0 -I {} cp -f {} dest_dir
Replace *.jpg
with format of your photo files. (e.g. *.png
etc.)
Note the use of -f
option of cp
, since you want to overwrite photos with the same name
Upvotes: 0
Reputation: 2330
find /path/to/source -type f | xargs -I {} file {} | grep <JPEG or image type> | cut -d ":" -f1 | xargs -I {} cp -rf {} /path/to/destination
With this you can find tune your copy with selecting only the image type.
Upvotes: 0
Reputation: 494
find /path/to/source -type f -exec cp -f {} /path/to/destination \;
Would that work? Keep in mind, that will overwrite files without asking.
If you want it to confirm with you before overwriting, use the -i flag (for interactive mode) in the cp
command.
Upvotes: 3