Linux 使用shell打印图形以显示文件总数和创建日期
我想创建一个直方图,Y轴上的总文件计数间隔为50,X轴上的创建时间以周为单位(即,如果在第1周和第2周之间创建了新文件,依此类推)Linux 使用shell打印图形以显示文件总数和创建日期,linux,bash,shell,awk,csh,Linux,Bash,Shell,Awk,Csh,我想创建一个直方图,Y轴上的总文件计数间隔为50,X轴上的创建时间以周为单位(即,如果在第1周和第2周之间创建了新文件,依此类推) 5500 +-+-----+-------+------+-------+-----+-+ 5000 +-+ ********* + + + +-+ 4500 +-+ * * ******** +-+ 4000 +-+ * * *
5500 +-+-----+-------+------+-------+-----+-+
5000 +-+ ********* + + + +-+
4500 +-+ * * ******** +-+
4000 +-+ * * * * +-+
3500 +-+ * * * * +-+
3000 +-+ * * * * +-+
2500 +-+ * ********* * +-+
2000 +-+ * * * * +-+
1500 +-+ * * * * +-+
1000 +-+ * + * + * + ********* +-+
500 +-+-********************************-+-+
0 1 2 3 4 5
差不多
5500 +-+-----+-------+------+-------+-----+-+
5000 +-+ ********* + + + +-+
4500 +-+ * * ******** +-+
4000 +-+ * * * * +-+
3500 +-+ * * * * +-+
3000 +-+ * * * * +-+
2500 +-+ * ********* * +-+
2000 +-+ * * * * +-+
1500 +-+ * * * * +-+
1000 +-+ * + * + * + ********* +-+
500 +-+-********************************-+-+
0 1 2 3 4 5
在某一周内创建了200、150、100、50个文件
Y轴上的7、14、21、28天。对如何实现这一点有些迷茫。谢谢你的帮助
5500 +-+-----+-------+------+-------+-----+-+
5000 +-+ ********* + + + +-+
4500 +-+ * * ******** +-+
4000 +-+ * * * * +-+
3500 +-+ * * * * +-+
3000 +-+ * * * * +-+
2500 +-+ * ********* * +-+
2000 +-+ * * * * +-+
1500 +-+ * * * * +-+
1000 +-+ * + * + * + ********* +-+
500 +-+-********************************-+-+
0 1 2 3 4 5
更新:我正在沿着这些路线努力
find <dirname> -type f -ctime -1 -ctime -7 | wc -l
find <dirname> -type f -ctime +7 -ctime -14 | wc -l
5500 +-+-----+-------+------+-------+-----+-+
5000 +-+ ********* + + + +-+
4500 +-+ * * ******** +-+
4000 +-+ * * * * +-+
3500 +-+ * * * * +-+
3000 +-+ * * * * +-+
2500 +-+ * ********* * +-+
2000 +-+ * * * * +-+
1500 +-+ * * * * +-+
1000 +-+ * + * + * + ********* +-+
500 +-+-********************************-+-+
0 1 2 3 4 5
find-type f-ctime-1-ctime-7 | wc-l
查找-类型f-ctime+7-ctime-14 | wc-l
找到最大值并将其用作我的X轴上限。然后将这个数字分成相等的间隔,以绘制我的X轴(抱歉是ksh而不是bash(bash级别接近echo“Hello World”):)
5500 +-+-----+-------+------+-------+-----+-+
5000 +-+ ********* + + + +-+
4500 +-+ * * ******** +-+
4000 +-+ * * * * +-+
3500 +-+ * * * * +-+
3000 +-+ * * * * +-+
2500 +-+ * ********* * +-+
2000 +-+ * * * * +-+
1500 +-+ * * * * +-+
1000 +-+ * + * + * + ********* +-+
500 +-+-********************************-+-+
0 1 2 3 4 5
这能满足你的需要吗
#!/bin/ksh
######################################
#
# statDirReport.sh
#
version="1.0"
# Andre Gelinas, 2018
#
######################################
#############
# Variables
#############
typeset -F2 SCALE
# Max value of X
X_SCALE=30
#############
# Main
#############
if [[ -n $1 ]]; then
DIRNAME=$1
else
print -n "Enter full path to stat : "; read DIRNAME
fi
if [[ ! -d $DIRNAME || ! -r $DIRNAME || ! -x $DIRNAME ]]; then
print "ERROR - Directory unusable - Exiting"
exit
fi
## Getting the data
CTIME1=1
CTIME2=0
for ((i=1;i<=4;i++)); do
CTIME2=$(($i*7))
FILE_COUNT[$i]=$(find $DIRNAME -type f -ctime +$CTIME1 -ctime -$CTIME2 | wc -l)
#To find late on the max amount
F_COUNT[${FILE_COUNT[$i]}]=${FILE_COUNT[$i]}
#
CTIME1=$CTIME2
done
#Doing some math
## Highest number of file
MAX_COUNT=${F_COUNT[-1]}
## Find the value of each tick
SCALE=$(($MAX_COUNT/$X_SCALE))
## Find the real length of the histogram for each week
## having the highest amount using full x scale (integer mathematics)
for ((i=1;i<=4;i++)); do
DATA_2_SCALE[$i]=$(((${FILE_COUNT[$i]}*$X_SCALE)/$MAX_COUNT))
done
# Getting the report
typeset -L2 Col1
typeset -L1 Col2
typeset -L$(($X_SCALE+5)) Col3
typeset -L5 Col4
Col1="Wk"
Col2=" "
Col3="Data"
Col4="Real"
clear
print "statDirReport v$version\tScale is #=$SCALE\n"
print "$Col1$Col2$Col3$Col4\n"
for ((i=1;i<=4;i++)); do
Col1=$i
Col2="|"
graph=""
Col4=${FILE_COUNT[$i]}
for ((j=1;j<=${DATA_2_SCALE[$i]};j++)); do
graph+="#"
done
Col3=$graph
print "$Col1$Col2$Col3$Col4"
done
5500 +-+-----+-------+------+-------+-----+-+
5000 +-+ ********* + + + +-+
4500 +-+ * * ******** +-+
4000 +-+ * * * * +-+
3500 +-+ * * * * +-+
3000 +-+ * * * * +-+
2500 +-+ * ********* * +-+
2000 +-+ * * * * +-+
1500 +-+ * * * * +-+
1000 +-+ * + * + * + ********* +-+
500 +-+-********************************-+-+
0 1 2 3 4 5
#/bin/ksh
######################################
#
#statDirReport.sh
#
version=“1.0”
#安德烈·格里纳斯,2018年
#
######################################
#############
#变数
#############
排版-F2比例
#X的最大值
X_标度=30
#############
#主要
#############
如果[[-n$1]];然后
DIRNAME=$1
其他的
打印-n“输入统计的完整路径:”;读名字
fi
如果[!-d$DIRNAME | |!-r$DIRNAME | |!-x$DIRNAME]];然后
打印“错误-目录不可用-正在退出”
出口
fi
##获取数据
CTIME1=1
CTIME2=0
对于((i=1;i以ksh而不是bash表示歉意(bash级别接近“Hello World”):)
5500 +-+-----+-------+------+-------+-----+-+
5000 +-+ ********* + + + +-+
4500 +-+ * * ******** +-+
4000 +-+ * * * * +-+
3500 +-+ * * * * +-+
3000 +-+ * * * * +-+
2500 +-+ * ********* * +-+
2000 +-+ * * * * +-+
1500 +-+ * * * * +-+
1000 +-+ * + * + * + ********* +-+
500 +-+-********************************-+-+
0 1 2 3 4 5
这能满足你的需要吗
#!/bin/ksh
######################################
#
# statDirReport.sh
#
version="1.0"
# Andre Gelinas, 2018
#
######################################
#############
# Variables
#############
typeset -F2 SCALE
# Max value of X
X_SCALE=30
#############
# Main
#############
if [[ -n $1 ]]; then
DIRNAME=$1
else
print -n "Enter full path to stat : "; read DIRNAME
fi
if [[ ! -d $DIRNAME || ! -r $DIRNAME || ! -x $DIRNAME ]]; then
print "ERROR - Directory unusable - Exiting"
exit
fi
## Getting the data
CTIME1=1
CTIME2=0
for ((i=1;i<=4;i++)); do
CTIME2=$(($i*7))
FILE_COUNT[$i]=$(find $DIRNAME -type f -ctime +$CTIME1 -ctime -$CTIME2 | wc -l)
#To find late on the max amount
F_COUNT[${FILE_COUNT[$i]}]=${FILE_COUNT[$i]}
#
CTIME1=$CTIME2
done
#Doing some math
## Highest number of file
MAX_COUNT=${F_COUNT[-1]}
## Find the value of each tick
SCALE=$(($MAX_COUNT/$X_SCALE))
## Find the real length of the histogram for each week
## having the highest amount using full x scale (integer mathematics)
for ((i=1;i<=4;i++)); do
DATA_2_SCALE[$i]=$(((${FILE_COUNT[$i]}*$X_SCALE)/$MAX_COUNT))
done
# Getting the report
typeset -L2 Col1
typeset -L1 Col2
typeset -L$(($X_SCALE+5)) Col3
typeset -L5 Col4
Col1="Wk"
Col2=" "
Col3="Data"
Col4="Real"
clear
print "statDirReport v$version\tScale is #=$SCALE\n"
print "$Col1$Col2$Col3$Col4\n"
for ((i=1;i<=4;i++)); do
Col1=$i
Col2="|"
graph=""
Col4=${FILE_COUNT[$i]}
for ((j=1;j<=${DATA_2_SCALE[$i]};j++)); do
graph+="#"
done
Col3=$graph
print "$Col1$Col2$Col3$Col4"
done
5500 +-+-----+-------+------+-------+-----+-+
5000 +-+ ********* + + + +-+
4500 +-+ * * ******** +-+
4000 +-+ * * * * +-+
3500 +-+ * * * * +-+
3000 +-+ * * * * +-+
2500 +-+ * ********* * +-+
2000 +-+ * * * * +-+
1500 +-+ * * * * +-+
1000 +-+ * + * + * + ********* +-+
500 +-+-********************************-+-+
0 1 2 3 4 5
!/bin/ksh
######################################
#
#statDirReport.sh
#
version=“1.0”
#安德烈·格里纳斯,2018年
#
######################################
#############
#变数
#############
排版-F2比例
#X的最大值
X_标度=30
#############
#主要
#############
如果[[-n$1]];则
DIRNAME=$1
其他的
打印-n“输入统计的完整路径:”;读取目录名
fi
如果[!-d$DIRNAME | |!-r$DIRNAME | |!-x$DIRNAME]];那么
打印“错误-目录不可用-正在退出”
出口
fi
##获取数据
CTIME1=1
CTIME2=0
对于((i=1;i在主目录上使用feedgnuplot
):
dirname=~
e=0
for f in `seq 7 7 28` ; do
find "${dirname}" -type f -ctime +$e -ctime -$f | wc -l
e=$f
done 2> /dev/null |
feedgnuplot --terminal 'dumb 50,15' --with boxes --unset grid --exit
5500 +-+-----+-------+------+-------+-----+-+
5000 +-+ ********* + + + +-+
4500 +-+ * * ******** +-+
4000 +-+ * * * * +-+
3500 +-+ * * * * +-+
3000 +-+ * * * * +-+
2500 +-+ * ********* * +-+
2000 +-+ * * * * +-+
1500 +-+ * * * * +-+
1000 +-+ * + * + * + ********* +-+
500 +-+-********************************-+-+
0 1 2 3 4 5
输出:
5500 +-+-----+-------+------+-------+-----+-+
5000 +-+ ********* + + + +-+
4500 +-+ * * ******** +-+
4000 +-+ * * * * +-+
3500 +-+ * * * * +-+
3000 +-+ * * * * +-+
2500 +-+ * ********* * +-+
2000 +-+ * * * * +-+
1500 +-+ * * * * +-+
1000 +-+ * + * + * + ********* +-+
500 +-+-********************************-+-+
0 1 2 3 4 5
在主目录上使用feedgnuplot
:
dirname=~
e=0
for f in `seq 7 7 28` ; do
find "${dirname}" -type f -ctime +$e -ctime -$f | wc -l
e=$f
done 2> /dev/null |
feedgnuplot --terminal 'dumb 50,15' --with boxes --unset grid --exit
5500 +-+-----+-------+------+-------+-----+-+
5000 +-+ ********* + + + +-+
4500 +-+ * * ******** +-+
4000 +-+ * * * * +-+
3500 +-+ * * * * +-+
3000 +-+ * * * * +-+
2500 +-+ * ********* * +-+
2000 +-+ * * * * +-+
1500 +-+ * * * * +-+
1000 +-+ * + * + * + ********* +-+
500 +-+-********************************-+-+
0 1 2 3 4 5
输出:
5500 +-+-----+-------+------+-------+-----+-+
5000 +-+ ********* + + + +-+
4500 +-+ * * ******** +-+
4000 +-+ * * * * +-+
3500 +-+ * * * * +-+
3000 +-+ * * * * +-+
2500 +-+ * ********* * +-+
2000 +-+ * * * * +-+
1500 +-+ * * * * +-+
1000 +-+ * + * + * + ********* +-+
500 +-+-********************************-+-+
0 1 2 3 4 5
这是将GNU awk用于时间函数的开始(未经测试,因为您没有提供我们可以测试的简明、可测试的示例输入):
5500 +-+-----+-------+------+-------+-----+-+
5000 +-+ ********* + + + +-+
4500 +-+ * * ******** +-+
4000 +-+ * * * * +-+
3500 +-+ * * * * +-+
3000 +-+ * * * * +-+
2500 +-+ * ********* * +-+
2000 +-+ * * * * +-+
1500 +-+ * * * * +-+
1000 +-+ * + * + * + ********* +-+
500 +-+-********************************-+-+
0 1 2 3 4 5
查找“$1”-键入f-printf“%T@%p\0”|
awk-v RS='\0''
开始{
nowSecs=systime()
}
{
fileName=gensub(/\S+\S+/,“”,1)
fileModSecs=int($1)
fileAgeSecs=nowSecs-fileModSecs
fileAgeDays=int(fileAgeSecs/(24*60*60))
fileAgeWeeks=int(fileAgeDays/7)
周数=fileAgeWeeks+1
文件编号[每周编号]++
周数=(周数>周数?周数:周数)
maxFileCnt=(fileCnts[weekNr]>maxFileCnt?fileCnts[weekNr]:maxFileCnt)
打印nowSecs、fileModSecs、fileAgeSecs、fileAgeDays、fileAgeWeeks、weekNr、fileName |“cat>&2”
}
结束{
对于(fileCnt=maxFileCnt;fileCnt>0;fileCnt--){
对于(weekNr=1;weekNr这是一个开始,将GNU awk用于时间函数(未经测试,因为您没有提供我们可以测试的简明、可测试的样本输入):
5500 +-+-----+-------+------+-------+-----+-+
5000 +-+ ********* + + + +-+
4500 +-+ * * ******** +-+
4000 +-+ * * * * +-+
3500 +-+ * * * * +-+
3000 +-+ * * * * +-+
2500 +-+ * ********* * +-+
2000 +-+ * * * * +-+
1500 +-+ * * * * +-+
1000 +-+ * + * + * + ********* +-+
500 +-+-********************************-+-+
0 1 2 3 4 5
查找“$1”-键入f-printf“%T@%p\0”|
awk-v RS='\0''
开始{
nowSecs=systime()
}
{
fileName=gensub(/\S+\S+/,“”,1)
fileModSecs=int($1)
fileAgeSecs=nowSecs-fileModSecs
fileAgeDays=int(fileAgeSecs/(24*60*60))
fileAgeWeeks=int(fileAgeDays/7)
周数=fileAgeWeeks+1
文件编号[每周编号]++
周数=(周数>周数?周数:周数)
maxFileCnt=(fileCnts[weekNr]>maxFileCnt?fileCnts[weekNr]:maxFileCnt)
打印nowSecs、fileModSecs、fileAgeSecs、fileAgeDays、fileAgeWeeks、weekNr、fileName |“cat>&2”
}
结束{
对于(fileCnt=maxFileCnt;fileCnt>0;fileCnt--){
对于(weekNr=1;weekNrDraw how?在带有“ASCII图”(like)的终端中,或者使用生成图形的外部工具,like?或者您是否希望编写一个直接执行此操作的shell脚本?这将非常广泛。使用shell脚本进行绘制。例如,在第1周,我有200个文件,它将在200天和7天(1周)的交叉处放置一个“X”有点。所以我首先需要找到在一周内创建的最大文件数,将其作为X轴的上限,然后将其划分为4-5个相等的间隔进行绘图。有什么简单的方法吗?只是用我正在尝试的内容更新了原始帖子。你知道UNIX不存储文件创建时间,所以无法获得除非您在创建文件时自己将其记录在某个地方,否则该信息是更改时间,而不是创建时间。如何在终端中使用“ASCII图”(如)绘制,或使用外部工具生成图形,如?或您想编写一个直接执行此操作的shell脚本吗?这将非常广泛。使用shell脚本绘制。例如,在第1周,我有200个文件,它将在200天和7天(1周)的交叉处放置一个“X”有点。所以我首先需要找到在一周内创建的最大文件数,将其作为X轴的上限,然后将其划分为4-5个相等的间隔进行绘图。有什么简单的方法吗?只是用我正在尝试的内容更新了原始帖子。你知道UNIX不存储文件创建时间,所以无法获得除非你在创建文件时自己在某处记录这些信息,对吗?ctime
是更改时间,而不是创建时间。谢谢!我只是在上面的上下文中查找了seq的功能。“dumb 50,15”的功能是什么?还试图了解绘图的工作原理。它是否显示了最大文件cr