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

5
  • 1
    possible duplicate of How do I remove hidden backup files?
    – rusty
    Mar 21, 2014 at 4:54
  • It's not duplicate i want to delete in the whole system not in a single place
    – user260119
    Mar 21, 2014 at 4:56
  • for that you'd use sudo find / ... ... [not recommended] to adapt the answer in the link 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, 2014 at 5: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, 2014 at 5:02
  • Why i should not do it for the whole system?!! how could it be end with broken system?
    – user260119
    Mar 21, 2014 at 5:04

1 Answer 1

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.

4
  • 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, 2014 at 5: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. Mar 21, 2014 at 5:19
  • @RaduRădeanu what about using -ok instead of -exec? With -ok, the deletion will be interactive. Please comment!
    – DK Bose
    Mar 21, 2014 at 18:23
  • @DKBose OK; also you can use rm -i instead of rm -f for the same purpose. Mar 21, 2014 at 18:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .