1

search for files and delete from the whole system file

If you create a file or just open a file with some programs like gedit, it will make auto save files named like this file~. For example if i do this gedit file.txt then when i close the file i can find two files file.txt and file.txt~.

What i want to do is to search the "/" whole file system for these files and then delete them. Note that those files could be other things not just text files.Thanks foe helping

rusty
  • 16,327
user260119
  • 113
  • 1
  • 1
  • 6

1 Answers1

1

To delete all backup files ending in ~ from the whole system, you can use:

sudo find / -type f -name '*~' -exec rm -f {} \;

Warning: I suggest you to run first find / -type f -name '*~' to see exactly what you will delete.

Radu Rădeanu
  • 169,590
  • This will not work if there is an extension. Am i right? since ~ will not include files that has more than something like ~.txt – user260119 Mar 21 '14 at 05:15
  • *~.txt ?!?! Doesn't exists such kind of backup files AFAIK. Only if you created manually. It's about *.txt~ and yes, my answer will work for these files, too. – Radu Rădeanu Mar 21 '14 at 05:19
  • @RaduRădeanu what about using -ok instead of -exec? With -ok, the deletion will be interactive. Please comment! – DK Bose Mar 21 '14 at 18:23
  • @DKBose OK; also you can use rm -i instead of rm -f for the same purpose. – Radu Rădeanu Mar 21 '14 at 18:56