如何处理bash中的每一秒文件? [英] How to process every second file in bash?

查看:25
本文介绍了如何处理bash中的每一秒文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 this I process all files:

find ./dir/ -type f -exec cat {} ;

解决方案

cnt=0; 
for file in $(find ./dir -type f); <-- if not too many matches
do 
  let cnt=cnt+1; 
  if [ $cnt -eq 2 ]; 
    then echo $file;               <-- do something
    cnt=0;                         <-- alternate file
  fi; 
done

or

second_file=$(find -type f | head -2 | tail -1);

这篇关于如何处理bash中的每一秒文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆