2

I have a directory with file names as " 202.png, 405.png, 0052.png, 04050.png, ...... I need a find command to find filenames excluding zeros that appear in the beginning of the file name. For example if i have a file with file name 00504.png then when I pass argument 504.png to find command it has to return the filename 00504.png which is actual name of the file in the directory.

Expected output command is

$ find . -name 504.png

It has to return the original filename which is 00504.png

3

As far as I know, the find command's -name only supports simple glob matches. However you could use -regex to match 504.png prefixed by zero or more 0 characters:

find . -regex '.*/0*504.png'

The leading .*/ is because -regex is a full path match.


If you don't need a recursive search, then shells such as bash may provide extended globs that allow expressions like *(0)

printf '%s\n' *(0)504.png

Check the documentation for the shell you are using.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.