Delete all backup files on Linux using Shell script recursively

How to delete all backup files, i.e. files ending with ~ , recursively in a specific folder in Ubuntu?

A script in any programming language.

+7
source share
3 answers

First, you can use the simple find :

 find . -type f -name '*~' -delete 
+18
source

One of the methods:

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

Basically, look at "man find"

0
source

First, what do you mean by recursively? Recursion is a convenient way to implement dome algorithms, but tends to be overused, but some people also use the term to search the directory tree (which can be implemented in other ways that are recursive). If you just want to delete all files matching a specific glob in the directory tree, then ...

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

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

0
source

All Articles