Copying photos / housekeeping in Linux (Ubuntu)


(Andrew) #1

I need to do some housekeeping, moving files around, but despite having a look around, I’m rather stuck, it’s going to take me ages to crack this… So please can anyone help?

What I want to do: Copy files from one set of folders to one destination folder. The source is a named folder plus all the subfolders under it, and all the ones under them, and so on. I want to specify a string that all the source file filenames (excluding the “extension”) must contain in order to be copied. As an example this might be “srgb”. I also want to specify a string that the extension must contain (or actually be) for example “jpg”. I’d like the string matching not to be case sensitive. These two string matches are “and” rather than “or”.

So I could do with some commands to Bash where I edit in:
source folder
destination folder
filename match string
extension match string

If when copying, the file is already in the destination, then it can be overwritten, or the file skipped, whatever is easier.

There will probably be whizzo ways of doing this, ideally I’d like something “step-by-step simple” that I might be abe to adapt myself if the need arises. I’m rather stuck how to start at present.
Thanks.


(pphoto) #2

For me it looks like you can do that with the Double Commander:
https://doublecmd.sourceforge.io/

You can search for files with wildcards, for ex.
*srgb*.jpg

Double Commander lists all found files and you can copy them into another folder


(Flössie) #3

Looks like this can be done with find -iname ... -exec cp "{}" /abs/path/to/dest \;. See the man page for the exact parameters.


(Morgan Hardwood) #4

Find *.jpg and *.dng files in ~/purgatory and all sub-folders, and send them to ~/hell while preserving the folder structure:

cd ~
find purgatory -type f \( -iname "*.jpg" -or -iname "*.dng" \) -exec cp -v --parents '{}' ~/hell \;

Why “cd ~” and “find purgatory” instead of just “find ~/purgatory”? Because the former would reproduce the /home/you/ folder structure in the target folder, which you probably don’t want, so the “cd ~” avoids that.


(Andrew) #5

Thanks folks, that’s great, it’s sorted. I ended up with

find INPUTFOLDER -type f ( -iname “sRGB.jpg" -or -iname ".xxx” ) -exec cp --preserve -v ‘{}’ OUTPUTFOLDER ;

a bit of a combo of the above, and I added preserve to keep the modified date. Cheers.