# Ideal means run a command on each documents in a directory tree

There show up be a variety of means to do this consisting of loopholes in covering manuscript, find and also xargs. Which of these is best, and also which is most mobile?

0
2019-05-05 01:50:20
Source Share

Make sure the variation of the command you're making use of does not currently have a flag for recursive procedure. :)

0
2019-05-08 11:37:06
Source
find . -exec <command> {} \;

.

for the existing directory as the origin of the tree or as a whole :

find <directory> -exec <command> {} \;

.
0
2019-05-08 09:52:58
Source

Use the -print0 alternative to find and also the -0 alternative to xargs if you have documents or directory names with rooms :

find {dir} -print0 | xargs -0r {command}


The -print0 alternative to find prints out the filenames as a NUL - apart as opposed to whitespace apart checklist, while the -0 alternative to xargs advises it to damage its input on NUL as opposed to whitespace. Given that NUL is just one of the personalities that is not admitted Unix filenames, there is no other way for it to be misinterpreted for component of a filename.

The -r alternative exists to make sure that xargs will not offer you a mistake if it has no input.

0
2019-05-08 09:48:29
Source

If transportability is a concern I would certainly steer clear of from covering - details means of doing it (there are great deals of individuals making use of great deals of various coverings, yet as a whole find and also xargs are actually standard devices that no person would certainly risk transform in an extreme means).

Making use of standard debates of find and also xargs need to offer you an extra mobile remedy.

0
2019-05-08 09:40:09
Source

If organizing debates with each other serves, find | xargs will possibly offer far better performance, given that it will certainly execute the command a whole lot less times than find - director. If you intend to execute the command each time for each and every documents or execute in the subdirectory of the documents you need to possibly make use of find - director or - execdir.

Generally, it's better to steer clear of from shell - details loopholes ; find & xargs suffice for the majority of circumstances.

0
2019-05-08 09:03:40
Source
find [args] -print | xargs {command}

.

Functions ideal for me.

0
2019-05-08 08:41:30
Source