使用Shell脚本递归删除Linux中的所有备份文件[复制]

时间:2022-10-16 00:13:22

How can I remove all backup files, i.e files ending with ~, recursively in a particular folder in Ubuntu?

如何在Ubuntu中的特定文件夹中以递归方式删除所有备份文件,即以〜结尾的文件?

A script in any programming language would do.

任何编程语言的脚本都可以。

3 个解决方案

#1


18  

For one, you could use a simple find command:

首先,您可以使用简单的find命令:

find . -type f -name '*~' -delete

#2


0  

One way:

单程:

find folder -name '*~' -print0 | xargs -0 rm -f

Basically, look at "man find"

基本上,看看“找人”

#3


0  

First off, what do you mean by recursively? Recursion is a convenient way to implement dome algorithms, but tends to be over-used - but some people also apply the term to searching a directory tree (which can be implemented by other means that recursion). If you simply want to delete all files matching a specific glob in a directory tree then....

首先,递归是什么意思?递归是实现圆顶算法的一种方便方法,但往往被过度使用 - 但是有些人也将该术语应用于搜索目录树(可以通过递归的其他方式实现)。如果您只想删除与目录树中特定glob匹配的所有文件,那么....

find /base/directory/ -type f -iname '*~' -exec rm -f {}\;

(but you might want to experiment with find /base/directory/ -type f -iname '*~' -exec ls -l {}\; first).

(但你可能想试试find / base / directory / -type f -iname'* ~'-exec ls -l {} \; first)。

#1


18  

For one, you could use a simple find command:

首先,您可以使用简单的find命令:

find . -type f -name '*~' -delete

#2


0  

One way:

单程:

find folder -name '*~' -print0 | xargs -0 rm -f

Basically, look at "man find"

基本上,看看“找人”

#3


0  

First off, what do you mean by recursively? Recursion is a convenient way to implement dome algorithms, but tends to be over-used - but some people also apply the term to searching a directory tree (which can be implemented by other means that recursion). If you simply want to delete all files matching a specific glob in a directory tree then....

首先,递归是什么意思?递归是实现圆顶算法的一种方便方法,但往往被过度使用 - 但是有些人也将该术语应用于搜索目录树(可以通过递归的其他方式实现)。如果您只想删除与目录树中特定glob匹配的所有文件,那么....

find /base/directory/ -type f -iname '*~' -exec rm -f {}\;

(but you might want to experiment with find /base/directory/ -type f -iname '*~' -exec ls -l {}\; first).

(但你可能想试试find / base / directory / -type f -iname'* ~'-exec ls -l {} \; first)。