Forrest logo
back to the find tool

files:delete:extension

Delete all files with the given extension
$ find ${directory} -type f -name '*.${extension}' -delete
try on your machine

This command is using the find command with certain options to search for files in a specific directory and delete them based on their name and file type.

Here's a breakdown of the command:

  • find: This is a command-line utility in Unix-like operating systems used to search for files and directories in a given location hierarchy.

  • ${directory}: This is a placeholder for the directory path where you want to start the search. You need to replace ${directory} with the actual path of the directory you want to search in.

  • -type f: This option specifies that the search should be limited to regular files only (not directories, symbolic links, etc.).

  • -name '*.${extension}': This option specifies the pattern or filename that should be matched. The '*.${extension}' pattern means that the filename should end with a period followed by a specific value of ${extension}. You need to replace ${extension} with the actual file extension you want to match.

  • -delete: This option is used to delete the files found during the search.

So, in summary, the command will find all regular files in the specified directory (and its subdirectories) that have a specific file extension and delete them.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.

Questions that are answered by this command:

  • How do i delete all files with given extension recursively?
back to the find tool