Linux – Delete all directory that begin with a particular string

directorylinuxrm

What command do I have to use to delete all directories that begin with graphene-80 under the directory /tmp?

What can I add to the rm command as option?

Best Answer

Using find command:

find /tmp -type d -name 'graphene-80*' -delete

Arguments used:

  • -type to filter directory only and avoid finding files
  • -name to find file that match the pattern define between quotes
  • -delete to delete the result of the find command

EDIT: cleaner with -delete like shown in this post: Find files matching template and remove