1

How can I delete every file on the system which have something in the name?

muru
  • 207,970
Goro
  • 113
  • 1
    Possible duplicate of: http://askubuntu.com/questions/443830/delete-all-files-that-contain-a-particular-string – TheWanderer May 18 '15 at 12:52

1 Answers1

3

Please be careful

This following command with the parameter -delete deletes all the files with something in the name in the specified directory and in all subdirectories.


Open a terminal and go to the right folder:

cd <your_search_starts_here>

test with

find . -type f -name "*something*"

and delete with

find . -type f -name "*something*" -delete

Or a shorter version:

find <your_search_starts_here> -type f -name "*something*" -delete

For your home folder:

  • !!! first run a test

    find ~ -type f -name "*something*"
    

    and than

    find ~ -type f -name "*something*" -delete
    

For the whole filesystem

  • !!! first run a test !!!

    sudo find / -type f -name "*something*"
    

    and test again and than delete with

    sudo find / -type f -name "*something*" -delete
    

Or only in the specified directory:

find <your_search_starts_here> -maxdepth 1 -type f -name "*something*" -delete

And because you have used the tag locate:

The results of a search with locate are based on a database. This may be outdated. Start an update with sudo updatedb. find performs a true search. However, it also takes longer.

Fabby
  • 35,075
A.B.
  • 92,275
  • That's the problem right folder .. those files are all across the system and it will be pain to navigate it to each folder and delete them. – Goro May 18 '15 at 12:26
  • As I wrote "This command deletes all the files with something in the name in the specified directory and in all subdirectories." – A.B. May 18 '15 at 12:27
  • So there is no way to say check the system, find "files" and delete them without to say first in this directory as I said is too much time consuming if I navigate to each directory where it has the file and then delete it. – Goro May 18 '15 at 12:30
  • 2
    Answered, read and please be careful. – A.B. May 18 '15 at 12:32
  • Thank's let me try it. It will be long long find.... I will post the result. – Goro May 18 '15 at 12:36
  • Strange.. whit locate file It found really a lot of that file.. but with sudo find / -type f -name "*something*" it found only ~10-15 results. – Goro May 18 '15 at 12:41
  • Also it didn't delete any file whit -delete. All files are still on the system – Goro May 18 '15 at 12:44
  • The search with locate is based on a database. This may be outdated. Start an update with sudo updatedb. find performs a true search. However, it also takes longer. – A.B. May 18 '15 at 12:44