for file in $1/*
do
if [ -f $file ]
then
SUFFIX=${file#*BK}
PREFIX=${SUFFIX%%_*}
CURRENT=`date -d -7day +%Y%m%d`
if [[ $CURRENT -gt $PREFIX ]]
then
rm -rf $file
fi
fi
done
#!bin/sh
for file in ./*
do
if test -f $file
then
echo $file 是文件
fi
if test -d $file
then
echo $file 是目录
fi
done
if --else 类型: #!bin/sh
for file in ./*
do
if test -f $file
then
echo $file 是文件
else
echo $file 是目录
fi
done

shell 遍历的更多相关文章

  1. shell遍历文件夹并执行命令

    背景: 有一个源码包里面包含很多子目录和makefile,打包后的压缩包太大,需要将make生成的所有二进制文件删除然后再打包. 需求: 因此,要求在制定目录的所有递归子目录中执行make clean ...

  2. shell遍历文件目录,监听文件变化,拼接字符串

    最近利用业余时间学习了shell 并做了个例子 实现的功能是 : 监听demo文件夹下的文件,只要新增了  .js的文件就把对应的文件名重组,拼接, 最后写入到demo.js里面. 文件结构如下 : ...

  3. Shell遍历文件,对每行进行正则匹配

    Shell查看文件的最后5行,并对每行进行正则匹配,代码如下: #!/bin/sh pattern="HeartBeat" /home/test/log/log_20150205. ...

  4. Shell 遍历字符串与参数

    遍历字符串: for line in  $Table_List do         echo $Table_List         echo $Table_List >> ${SYB_ ...

  5. shell遍历文件夹

    遍历目录下的所有文件 假如有一个文件夹路径为dir,遍历文件 for file in /path/dir/* do if test -f $file then echo $file arrary=($ ...

  6. unix 下 shell 遍历指定范围内的日期

    UNIX下遍历日期,date 没有 -d 的参数,所以需要自己处理. 下面使用时差的方法进行计算,遍历的日期是降序的 #!/usr/bin/ksh . $HOME/.profile timelag= ...

  7. Shell遍历目前下后缀名为.xml的文件并替换文件内容

    1.shell查找 .xml文件 find /home/esoon/test/external/ -type f -name '*.xml' 2.替换方法 sed -i "s/10.111. ...

  8. Shell遍历文件的每一行[转载]

    #!/bin/sh while read line do echo $line done < /home/jms/lab/input.txt

  9. Shell遍历文件的每一行

    由于使用for来读入文件里的行时,会自动把空格和换行符作为一样分隔符,因为当行里有空格的时候,输出的结果会很乱,所以…… cat input.txt |while read line> do&g ...

随机推荐

  1. ZOJ 3774 Fibonacci的K次方和

    In mathematics, Fibonacci numbers or Fibonacci series or Fibonacci sequence are the numbers of the f ...

  2. 新Linux系统配置yum源

    新的Linux系统安装好以后,yum的源还是需要配置一下的,我使用的是redhat6.6版本,同时为了不注册而使用更多的yum源的资源,也需要做一下的修改. 1. 删除redhat原有的yum源 # ...

  3. Tool1—安装配置Windows Live Writer

    详细步骤请看:http://home.cnblogs.com/group/topic/8550.html . Windows Live Writer手工配置步骤(在博客园配置时输入用户名与密码会自动完 ...

  4. cmd 使用gii的命令行用法

    1.生成模型 php yii gii/model --ns=common\models --tableName=contract_supplemental --modelClass=ContractS ...

  5. 修改ecshop后台的管理菜单

    ecshop后台菜单如何去修改,下面ecshop开发中心如何去修改 首先先打开后台菜单项相关文件: admin\includes\inc_menu.php languages\zh_cn\admin\ ...

  6. python批量替换文件名

    替换关键字 #-*-coding:utf-8-*- import os import re filepath = u'E:\\CMMI4\\07_测试文档' files = os.walk(filep ...

  7. Linux轻量级自动运维工具-Ansible浅析【转】

    转自 Linux轻量级自动运维工具-Ansible浅析 - ~微风~ - 51CTO技术博客http://weiweidefeng.blog.51cto.com/1957995/1895261 Ans ...

  8. WebHeaderCollection类

    .net添加http报头 string[] allKeys = WebHeaderCollection.AllKeys; for (int i = 0; i < allKeys.Length; ...

  9. 32.Longest Valid Parentheses---dp

    题目链接:https://leetcode.com/problems/longest-valid-parentheses/description/ 题目大意:找出最长的括号匹配的子串长度.例子:&qu ...

  10. centos-testlink安装使用手册

    1.新建虚拟机设置 网卡必须选择ovirtmgmt模式 2.Centos6.3系统安装 说明: 1.CentOS 6.3系统镜像有两个,安装系统只用到第一个镜像即CentOS-6.3-i386-bin ...