I have multiple files in this directory someDir
and I'm trying to move only the ones that have this ending O_010_0000000028181996.xml
I've checked my regular expression online and it matches,the problem is when I run my bash command the files do not get moved to the folder found
.
My command bash command is
find /home/someDir/ -regex '\d{10}.{3}O_010_0000000028181996\.xml' -exec mv '{}' /home/found/ \;
Example of filenames in directory someDir:
0208420319-1-O_010_0000000028174248.xml
0208461630-1-O_010_0000000028178356.xml
0208696934-1-O_010_0000000028181996.xml
0208696935-1-O_010_0000000028181996.xml
0208735127-1-O_010_0000000028186468.xml
0208774443-1-O_010_0000000028191308.xml
0208812611-1-O_010_0000000028196104.xml
0208858156-1-O_010_0000000028198984.xml
-regex
, not just the filename. Also, this has nothing to do withbash
, and everything to do with GNUfind
. – Kusalananda Mar 18 '21 at 09:39find
sees, including the path you set as argument-regex '/home/someDir/\d{10}.{3}O_010_0000000028181996\.xml'
or similar depending on whether there are subdirectories – muru Mar 18 '21 at 09:40find /home/someDir/ -regex '.*\.xml' -exec mv '{}' /home/found/ \;
– Cristian Mateica Mar 18 '21 at 09:48.*
covers the path. – muru Mar 18 '21 at 09:52find /home/someDir/ -regex '/home/someDir/\d{10}.{3}O_010_0000000028181996\.xml' -exec mv '{}' /home/found/ \;
– Cristian Mateica Mar 18 '21 at 09:55find
implementation are you using? At least with GNU find, AFAIK none of the built-in regextypes supports the PCRE\d
for a decimal digit. Probably the closest you'll get is-regextype egrep -regex '.*/[0-9]{10}.{3}O_010_0000000028181996\.xml'
– steeldriver Mar 18 '21 at 12:11