问题
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