Linux 如何查找文件名以波浪号结尾的所有文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7501697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to find all files with a filename that ends with tilde
提问by nothing-special-here
I use Emacs and it sometimes makes backup for edited files. After a few days, I would have a lot of backup files whose name ends with a tilde.
我使用 Emacs,它有时会备份编辑过的文件。几天后,我会有很多名称以波浪号结尾的备份文件。
Is there a way to find these files and delete them at once?
有没有办法找到这些文件并立即删除它们?
I tried this:
我试过这个:
find "*" -type f -iname *~
But it doesn't work. I want the command to work recursively – something like ls -alR
.
但它不起作用。我希望命令递归地工作 - 类似于ls -alR
.
采纳答案by Drakosha
You need to escape from the shell. And you need to specify search path, not *
您需要从外壳中逃脱。并且您需要指定搜索路径,而不是*
find . -type f -name '*~'
To delete the files:
要删除文件:
find . -type f -name '*~' -exec rm -f '{}' \;
回答by GaetanJUVIN
You can do something like that :
你可以这样做:
find . -type f -name '*~' -delete
If you want to delete also #*# file :
如果您还想删除 #*# 文件:
find . -type f -name '*~' -o -name '#*#' -delete
You can print all deleted files with "-print":
您可以使用“-print”打印所有已删除的文件:
find . -type f -name '*~' -delete -print
回答by zee
Another way is by using grep.
另一种方法是使用 grep。
lnydex99uhc:javastuff user$ ls
Permutation.java VigenereCipher.java VigenereCipher.java~
lnydex99uhc:javastuff user $ find . | grep .~$
./VigenereCipher.java~
You can also pass any command you want like this :
你也可以像这样传递任何你想要的命令:
lnydex99uhc:javastuff zatef$ rm $(find . | grep .~$)