If you want to search files by a pattern and then apply something to the results you have at least two choices. You can use find. There are also two different choices for find -exec and find xargs that will have a dramatic impact on performance.
So what is the difference and which one should you choose? Search for files only that end with. You have to use both or neither of them. The advantage is that all results will be handed over to xargs as a single string without newline separation. NUL charater separation is a way to escape files which also contain spaces in their filenames. This is equal to:. If no -n[int] is specified, xargs uses the default of -n see man xargs. Exec does not have this problem.
Every time exec processes a file or directory, it needs to start a command, which is not efficient;. The format of exec is troublesome. In summary, if the command to be used supports processing multiple files at a time, and also knows that there are no files with spaces in these files, then it is more convenient to use xargs; otherwise, you must use exec. Write My Article. Suppose find commands finds 2 files a.
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 8 years, 11 months ago.
Active 7 years, 1 month ago. Viewed 7k times. I am trying to search for the string "rGEO" in a directory by using the following commands: find. Using xargs gives more clear and precise output. Improve this question. Mat k 39 39 gold badges silver badges bronze badges. Subhayan Bhattacharya Subhayan Bhattacharya 4, 4 4 gold badges 31 31 silver badges 47 47 bronze badges.
Not quite a duplicate of Which is faster, 'find -exec' or 'find xargs -0'? More to the point: find -exec is pretty much identical to find -print0 xargs -0n1 since -n1 ensures one call per result.
0コメント