Search code examples
linuxfindrm

how to delete all files with a path pattern


I have a backup location, which uses hardlinks to store existing or changed files. The location of these backups mimick the linux file system with a date part in it.

For example I have files

/backup/servername/2012-06-26T00.43.01/www.website.com/file1.html
/backup/servername/2012-06-26T06.43.01/www.website.com/file1.html
/backup/servername/2012-06-26T06.43.01/www.website.com/file2.html
/backup/servername/2012-06-26T12.43.01/www.website.com/file1.html
/backup/servername/2012-06-26T12.43.01/www.website.com/file2.html

How can I find all files which have www.website.com in them, so I can delete them

I have this command combination to delete files I can find with find, but I can't figure out how to find these files.

find . -name 'filename.*' -print0 | xargs -0 rm

Solution

  • You're being a little loose with your terminology, so it's a kind of tough to understand what exactly you want. However, if I understood you correctly, you want to delete all the files within a directory called www.website.com:

    find . -wholename '*/www.website.com/*.html' -delete