Search code examples
linuxshellrm

`find` claims it deleted the files, `ls` claims it didn't


I tried to delete some images by matching them to a regular expression and I did this in two similar ways by now, both including piping the results of find to rm. First I found all the images that I wish to be deleted with this:

find . -type f -regex ".+-[0-9]+x[0-9]+\.jpg"

Which found a lot of results.

So I tried to delete them like this:

find . -type f -regex ".+-[0-9]+x[0-9]+\.jpg" -exec rm -rf {} \;

And then like this:

find . -type f -regex ".+-[0-9]+x[0-9]+\.jpg" | xargs rm

After both attempts, the find command no longer sees the images that I wanted to delete (when I run the first command again), but ls sees them, and so does Nautilus. Is there some kind of commit I should run in order to actually delete them from the hard disk?

I tried searching the rm man page for "commit" and the find man page for "remove", but haven't found anything significant.


Solution

  • Your regex doesn't match these filenames...

    $ touch yellow-zone-etna-36x36.png yellow-zone-etna-615x250.png
    $ find . -type f -regex ".+-[0-9]+x[0-9]+\.jpg"
    $ # no output
    

    because you have PNGs, you're looking for JPEGs, and you additionally have JPEGs that don't match the regex either.