Find files with extension with 5 characters or more

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 01:43:26

问题


I have a lot of residue files from a failed rsync-command. They all have a file extension of 5 (random)characters. Is there a command that can find all files with an extension of 4 characters and more recursively?

Example of a rsync residue filename: foo.jpg.hzmkjt7

I've already found out a way to prevent this with rsync, but all I need to do now is clean those leftovers...


回答1:


Using bash, one option would be to use globstar like this:

shopt -s globstar # enable the shell option
echo **/*.?????   # to test which files are matched
rm **/*.?????     # if you're happy

The pattern matches any files in the current directory or any subdirectories that end in a . followed by 5 characters.

Rather than matching any character with a ?, you could go more specific by changing the glob to something like **/*.[[:alnum:]][[:alnum:]][[:alnum:]][[:alnum:]][[:alnum:]] to match 5 alphanumeric characters.




回答2:


You can write a regular expression for this:

find /your/dir -regextype posix-extended -regex '.*\..{4,}$'

That is, look for files that end with . together with 4 or more.

Idea on how to use a regex from How to use regex in file find.



来源:https://stackoverflow.com/questions/31314104/find-files-with-extension-with-5-characters-or-more

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!