How can I find files on Linux that have a filename shorter than n characters?
For example, to have something to work with, I am looking recursively for all filenames within /home/myuser
that are less than 5 characters long (so, a file with name foo
should be found, but with name barbaz
not because its name is longer than 4 characters) - how can I do so?
The -name
option of find
operates on the file name without the path. You can't say "shorter than" in a pattern, but you can say "longer than" and negate:
find . -not -name '?????*'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With