我有以下文件夹结构:
├── longdirectorywithsillylengththatyouwouldntnormallyhave
│ ├── asdasdads9ads9asd9asd89asdh9asd9asdh9asd
│ └── sinlf
└── shrtdir
├── nowthisisalongfile0000000000000000000000000
└── sfile我需要找到的文件和文件夹的名字,长度是大于x字符。我做到了以下几点:
find . -exec basename '{}' ';' | egrep '^.{20,}$'
longdirectorywithsillylengththatyouwouldntnormallyhave
asdasdads9ads9asd9asd89asdh9asd9asdh9asd
nowthisisalongfile0000000000000000000000000但是,这只会输出有关文件或文件夹的名称。如何输出如下结果匹配的完整路径:
/home/user/Desktop/longdirectorywithsillylengththatyouwouldntnormallyhave
/home/user/Desktop/longdirectorywithsillylengththatyouwouldntnormallyhave/asdasdads9ads9asd9asd89asdh9asd9asdh9asd
/home/user/Desktop/shrtdir/nowthisisalongfile0000000000000000000000000发布于 2018-04-12 08:35:58
如果对文件使用basename,则会丢失有关实际处理的文件的信息。
因此,您必须更改regex,以便能够识别最后一个路径组件的长度。
我能想到的最简单的方法是:
find . | egrep '[^/]{20,}$' | xargs readlink -f这利用了一个事实,即filenames cannot contain slashes。
结果包含相对于当前cwd的路径,从readlink到can be used为您提供完整的路径。
发布于 2018-04-12 07:29:07
我现在不能测试它,但这应该可以做到:
find $(pwd) -exec basename '{}' ';' | egrep '^.{20,}$'发布于 2018-04-12 09:08:06
find -name "????????????????????*" -printf "$PWD/%P\n" -printf的find选项非常强大。百分比P:
%P File's name with the name of the starting-point under which it was found removed. (%p starts with ./). 因此,我们增加$PWD/在前面。
/home/stefan/proj/mini/forum/tmp/Mo/shrtdir/nowthisisalongfile0000000000000000000000000
/home/stefan/proj/mini/forum/tmp/Mo/longdirectorywithsillylengththatyouwouldntnormallyhave
/home/stefan/proj/mini/forum/tmp/Mo/longdirectorywithsillylengththatyouwouldntnormallyhave/asdasdads9ads9asd9asd89asdh9asd9asdh9asd为了防止我们手工计算问号,我们使用:
for i in {1..20}; do echo -n "?" ; done; echo
????????????????????https://stackoverflow.com/questions/49790432
复制相似问题