Forrest logo
back to the find tool

shell:warp:99fb0

Search for specified file types and run a certain command for each file
$ find -E ${path} -iregex ".*\.(${extensions})" -print | xargs -n1 -I _item ${command} _item
try on your machine

This command is a combination of multiple command-line tools, used to find files with specific extensions in a given directory and perform a specified command on them.

Here is a breakdown of what each part of the command does:

  • find: The find command is used to search for files and directories in a specific location.
  • -E ${path}: This flag is used to specify the path or directory where the search should be performed (${path} is a placeholder for the actual path).
  • -iregex ".*\.(${extensions})": This flag is used to filter the search results based on a regular expression. It searches for files that match any of the given extensions (${extensions} is a placeholder for the extensions separated by |, e.g., jpg|png|gif).
  • -print: This flag is used to print the path of each file that matches the search criteria.
  • |: The pipe symbol is used to redirect the output from the find command and pass it as input to the next command.
  • xargs: The xargs command is used to construct and execute command lines from standard input.
  • -n1 -I _item: These flags specify that xargs should execute the command specified (${command} is a placeholder for the actual command) once for each input item, taking one at a time, and replacing the placeholder _item with the input item.
  • ${command} _item: This is the command that will be executed for each file found. _item is a placeholder for the filename.

In summary, this command locates files with specific extensions in a given directory, prints their paths, and then executes a specified command (replacing _item with each file's path) on each file found.

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.
back to the find tool