@ljm
2018-01-03T01:08:03.000000Z
字数 1205
阅读 1141
experiment
描述一下程序的功能需求吧:
从命令行输入一个目录,访问这个目录下的所有非目录文件,将所有的文件名shuffle,然后将shuffle后的文件名放入一个文本文件中,在文本之中,不同的文件名之间用'\0'间隔开。
python代码如下:
#!/usr/bin/pythonimport sysimport osimport randomif __name__ == "__main__":basepath = sys.argv[1] # get the pathlistfile = []dirs = os.listdir(basepath)for file in dirs:filepath = basepath + fileif(os.path.isfile(filepath)):listfile.append(file) # only remain the file name in the listrandom.shuffle(listfile) # shuffle the listlength = len(listfile) # writre the string list to file,and the seperate between the string is NULf = open("wlog.log", "w")i = 1for file in listfile:f.write('/'+file+'\0')f.write('\0')
运行代码:
chmod a+x test.py
sudo ./test.py /var/www/html/
sudo chmod 777 wlog.log
结果保留在wlog.log中
crfile可以生成文本文件。
从autobench官网下载autobench压缩包并安装,其自带crfile。
用法:
crfile -f filename -s size
-f filename
specifies the file to be created. If the file exists, an error is generated.
-s size
size is the size of the file, in bytes
demo:
crfile -f test1.txt -s 4096
编写了shell程序,生成测试数据:
#!/bin/bashnum_of_files=$1min_size=$2max_size=$3rm text*.txtfor (( c=1; c<=num_of_files; c++ ))dosize=$(shuf -i $min_size-$max_size -n 1)crfile -f text$c.txt -s $sizedone
usage:
1. chmod +x ./test.sh
2. ./test.sh 1000 1024 2048
- 第一个参数为生成文本文件的数目
- 第二个参数为文本文件size的最小值(以byte为单位)
- 第三个参数为文本文件size的最大值(以byte为单位)