Find files with a minimum filename length
I think the simplest way is to use:
find . -name "??????????*"
where the number of ?
characters is equal with n
. Is simple because is hard to forget it.
But the nicest way is to use the -regex
option to find file names with n
or more characters:
find . -regextype posix-egrep -regex ".*[^/]{n}"
where n
should be a natural number (the minimum filename length).
See man find
fore more about.
You could use the find
command with a -regex
test
$ find /path/to/folder -regextype posix-basic -regex '.*/.\{5,\}'
or
$ find /path/to/folder -regextype posix-extended -regex '.*/.{5,}'
Note that -regex
is a path match rather than a file match - hence you need to match the leading .*/
as well, before the 5+ character filename
Alternatively, for a pure bash solution, you could enable extended shell globbing and then use the pattern !(@(?|??|???|????))
meaning 'anything that does not match one or two or three or four characters'
$ shopt -s extglob
$ ls -d /path/to/folder/!(@(?|??|???|????))
If you want to include subdirectories, you can enable the globstar
option as well and add a **
wildcard i.e.
$ shopt -s extglob globstar
$ ls -d /path/to/folder/**/!(@(?|??|???|????))
for example
$ ls -d **/!(@(?|??|???|????))
abcde abcdef abcdefg subdir subdir/abcde subdir/abcdef subdir/abcdefg
while the non inverted matches (files shorter than 5 characters) are
$ ls -d **/@(?|??|???|????)
a ab abc abcd subdir/a subdir/ab subdir/abc subdir/abcd
To unset the options afterwards, use
$ shopt -u extglob globstar