Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find files on Linux with a name shorter than n characters?

Tags:

linux

find

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?

like image 861
Foo Bar Avatar asked Dec 08 '22 02:12

Foo Bar


1 Answers

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 '?????*'
like image 155
choroba Avatar answered Dec 11 '22 10:12

choroba