Bash: how to traverse directory structure and execute commands?

前端 未结 6 1580
半阙折子戏
半阙折子戏 2021-01-12 06:40

I have split a large text file into a number of sets of smaller ones for performance testing that i\'m doing. There are a number of directories like this:

/h         


        
6条回答
  •  执笔经年
    2021-01-12 06:53

    For this kind of thing I always use find together with xargs:

    $ find output-* -name "*.chunk.??" | xargs -I{} ./myexecutable -i {} -o {}.processed
    

    Now since your script processes only one file at a time, using -exec (or -execdir) directly with find, as already suggested, is just as efficient, but I'm used to using xargs, as that's generally much more efficient when feeding a command operating on many arguments at once. Thus it's a very useful tool to keep in one's utility belt, so I thought it ought to be mentioned.

提交回复
热议问题