如何查找 Linux 上名称短于 n 个字符的文件?

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

如何在 Linux 上找到文件名短于 n 个字符的文件?

例如,要处理某些内容,我正在递归查找 /home/myuser 中长度小于 5 个字符的所有文件名(因此,应该找到名称为 foo 的文件,但名称为 barbaz 不是因为它的名称超过 4 个字符)- 我该怎么做?

find-name选项对不带路径的文件名进行操作。你不能在模式中说 "shorter than",但你可以说 "longer than" 并取反:

find . -not -name '?????*'

请试试这个

find . -type f -exec basename {} \; | awk '{ if(length([=10=]) < n) print [=10=] }'

其中 'n' 不是。字符数