7

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

A script in any programming language would do.

IQAndreas
  • 8,060
  • 8
  • 39
  • 74
Janmejay
  • 1,013
  • 2
  • 13
  • 26

3 Answers3

18

For one, you could use a simple find command:

find . -type f -name '*~' -delete
knittl
  • 246,190
  • 53
  • 318
  • 364
0

One way:

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

Basically, look at "man find"

Chris
  • 4,133
  • 30
  • 38
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....

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).

symcbean
  • 47,736
  • 6
  • 59
  • 94