How to find files by the filename length in OS X 10.9.1?
Need to find files/folders with names longer than n characters (OS X 10.9.1).
Could you please help?
The most basic way is probably to use globbing:
find . -type f -name '???????????*'
This will list all files with a filename length greater than 10 characters. There are 11 question marks, and the asterisk matches those with longer length. Modify the number of question marks to match what you're looking for.
For greater than or equal to 10, use ??????????*
, or for equal to 10 use ??????????
.
You can use the find
command with the -regex
(regular expression) option. This is probably less efficient than globbing, because -regex
matches against the entire path.
find -E . \( -type f -or -type d \) -and -regex '.*/[^/]{11,}'
Precisely, this command does the following:
- recursively searches for files in the current folder and in the subdirectories (you can limit the depth with an additional
-maxdepth n
clause); - uses the extended syntax (
-E
) for regexes. - searches for files and folders (
-type f -or -type d
) - regex match: the string which follows the last slash in the file path must be 11 characters or longer.