How to process every second file in bash?

后端 未结 4 1273
忘掉有多难
忘掉有多难 2021-02-15 23:55

I have a directory with a few dozens of files. I would like to do something with every second file from this directory. By now I only used find command but with thi

4条回答
  •  悲&欢浪女
    2021-02-16 00:19

    If you want to run my_cmd on each of the alternate file, this may help

     find ./dir -type f | sort -n | sed -n '1~2!p'  | sed 's/^/mycmd  /' | sh
    

    I've copied the sed from How to remove every other line with sed?

提交回复
热议问题