linux下分区目录的shell脚本

发布时间:2019-11-04编辑:脚本学堂
本文介绍下,一个用于分区目录的shell脚本,有需要的朋友作个参考吧。

本文分享的这段shell脚本,用于linux中目录的分区,尤其适用于小目录包含有限数量的文件的情况,便于处理有数量庞大的文件的目录。

脚本内容如下:
 

复制代码 代码示例:

#!/bin/bash
#This script should be present in the parent directory of the directory which is supposed to
#be partitioned.
#The files in the input directory will be moved to each of these partitions
#eidt by www.jb200.com

if [ $# -ne 1 ]; then
    echo "usage: $0 directory_name" 1>&2
    exit 1
fi

dir="$1_partitioned"
mkdir $dir

subdir=1

mkdir "$dir/$subdir"
incr=0

for fname in $1/*
do
  if [ $incr -gt 1000 ]; then
      subdir=$((subdir+1))
      mkdir "$dir/$subdir"
      incr=0
  fi
  mv $fname "$dir/$subdir"
  incr=$((incr+1))
done

附,Cleanup ARCHIVE or LOG FILES in the UNIX Box 
How to clean up ARCHIVE or LOG FILES in the UNIX Box
 

复制代码 代码示例:
find /prod/data -type f -name "*.log" -mtime +92 -exec rm -f {} ;
find /prod/data -type f -name "*.csv" -mtime +92 -exec rm -f {} ;