I have a main folder that contains files and subfolders and I want to move all the graphic files (pdf, png, jpg, and so on) in a new folder callded figs (inside my main folder).
I want to exclude:
- all the subfolders whose name starts with
Copy_of_ - all the folders whose name contains
copy 1andtikz - all the
pdffiles whose name starts withCopy_of_,XXX,YYY,ZZZ
I wrote this code:
# not pdf
find . -type f -regextype posix-extended -regex '.*(jbig2|jpeg|jp2|jpg|jpx|png)$' ! -path '*/Copy_of_*/*' ! -path '*/*copia 1*/*' ! -path '*/tikz*/*' ! -path 'figs' -print0 | xargs -0 -I {} mv {} "figs"
# pdf
find . -type f \( -name "*.pdf" ! -name "Copy_of_*" ! -name "XXX*" ! -name "YYY*" ! -name "ZZZ*" \) ! -path '*/Copy_of_*/*' ! -path '*/*copy 1*/*' ! -path '*/tikz*/*' ! -path 'figs' -print0 | xargs -0 -I {} mv {} "figs"
I split my code into two parts because I can't manage it in one solution.
Is there a way to do it all with one call to find and/or to use regular expressions for -name and -path thus avoiding having to specify them one by one?