本文分享的这段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