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
  • 15,770
  • 11
  • 65
  • 92
user260119
  • 113
  • 1
  • 1
  • 6
  • 1
    possible duplicate of [How do I remove hidden backup files?](http://askubuntu.com/questions/317134/how-do-i-remove-hidden-backup-files) – rusty Mar 21 '14 at 04:54
  • It's not duplicate i want to delete in the whole system not in a single place – user260119 Mar 21 '14 at 04:56
  • for that you'd use `sudo find / ... ...` [not recommended] to adapt the [answer in the link](http://askubuntu.com/questions/317134/how-do-i-remove-hidden-backup-files) to suit your need.. but I don't think you need to do this, the system config file-backups won't take much space, and they could prove useful.. instead you can just do this for user-home directories `find $HOME ... ...` – rusty Mar 21 '14 at 05:02
  • **Do not delete in the whole system!** The filesystem is managed by Ubuntu itself and if you try collect garbage that way you may end up with broken system! – Danatela Mar 21 '14 at 05:02
  • Why i should not do it for the whole system?!! how could it be end with broken system? – user260119 Mar 21 '14 at 05:04

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
  • 166,822
  • 48
  • 327
  • 400
  • 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