Tuesday, May 14, 2024
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 834  / 2 Years ago, thu, june 2, 2022, 8:28:48

how can I find all files that contain embedded crc32's
e.g. Mydocument190_[F285E17D].pdf using the find command



to clarify the crc32's are always within brackets [F285E17D] and the file names may contain both capital lower-case letters and numbers



further clarification the crc32's are in the file name
and the purpose is to then pipe the results to another command for verification (a lot of files only some of which contain aforementioned crc32's)


More From » command-line

 Answers
0

I'd agree with Ahmed on many points (use find, use a regex, use posix-extended-mode) but for the implementation. There are a few problems:




  • find has a case-insensitive -iregex mode that makes this better by not needing to specify A-Z as well as a-z

  • Speaking of, CRCs are hexadecimal strings. We only want [0-F]… which I think we can specify as a single range. If it doesn't work, use [0-9a-f]

  • And we need to check for square brackets (or it'll just match any 8-char string).

  • -regex and -iregex search the whole path. We need to make sure your string isn't in a directory name so we exclude any slashes after the CRC.



Here's my current best effort:



find -regextype posix-extended -iregex '.*[[0-f]{8}][^/]*'


This will allow for extensionless files too.


[#24915] Thursday, June 2, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zombieptu

Total Points: 490
Total Questions: 121
Total Answers: 108

Location: Nepal
Member since Mon, Jan 4, 2021
3 Years ago
;