老李分享:《Linux Shell脚本攻略》 要点(三)
2015-12-15 17:37
761 查看
老李分享:《Linux Shell脚本攻略》 要点(三)
1、生产任意大小的文件[root@localhost dd_test]#
[root@localhost dd_test]# dd if=/dev/zero of=junk.data bs=1k count=10
10+0 records in
10+0 records out
10240 bytes (10 kB) copied, 0.00137023 s, 7.5 MB/s
2、文件系统相关测试
[ -f $file_var ]: 给定的变量包含正常的文件路径或文件名,则返回真
[ -d $var ]: 给定的变量是目录,则返回真。
[ -e $var ]: 给定的变量包含的文件存在,则返回真。
[ [ -z $str1 ]]: 如果str1包含的是空字符串,则返回真。
[ [ -n $str1 ]]: 如果str1包含的是非空字符串,则返回真。
-gt: 大于
-lt: 小于
-ge: 大于或等于.
-le: 小于或等于.
3、文件权限
[root@localhost program_test]# chmod 777 cnts.sh
4、批量生成任意大小的文件
[root@localhost touch_more]# cat create_morefile.sh
#!/bin/bash
for name in {1..100}.txt
do
touch $name
dd if=/dev/zero of=$name bs=1k count=1
done5、生成符号链接文件
[root@localhost touch_more]# ln -s 100.txt 100_symbol.txt
[root@localhost touch_more]# ll -al 100*
lrwxrwxrwx. 1 root root 7 Jan 2 00:24 100_symbol.txt -> 100.txt
-rw-r--r--. 1 root root 1024 Jan 2 00:22 100.txt
查找符号链接的文件
方法一:
[root@localhost touch_more]# ls -al | grep '^l' | awk '{print $9}' //特征标记,以l开头。
100_symbol.txt
方法二:
[root@localhost touch_more]# find ./ -type l
./100_symbol.txt
打印符号链接指向文件的名称:
[root@localhost touch_more]# ls -al 100_symbol.txt | awk '{ print $11 }'
100.txt
6、遍历文件,分类型统计文件
[root@localhost touch_more]# cat filestat.sh#!/bin/bash if [ $# -ne 1 ];then echo $0 basepath; exit 1fipath=$1 declare -A statarray; while read line;do ftype=$(file -b "$line") let statarray["$ftype"]++;done < <(find $path -type f -print) //以子进程统计文件名 echo ===================FILE types and counts =============== for ftype in "${!statarray[@]}"; //数组表do echo $ftype : ${statarray["$ftype"]}done6、实时观看不断增长的文件
[root@localhost touch_more]# tail -f filestat.sh
7、目录切换
[root@localhost program_test]# cd -
/home/yxx/program_test/touch_more
相关文章推荐
- 老李性能测试分享
- 你想不到:咖啡馆里上工具课
- 移动端自动化测试开课了
- 老李分享:什么是好战略
- 性能调优案例分享:Mysql的cpu过高
- 性能测试分享:性能测试工具开发的案例分享(上)
- 性能测试分享:性能测试工具开发的案例分享(下)
- 性能测试培训:批量执行Jmeter脚本之ant调用 2
- 性能测试培训:分布式测试之jmeter1
- 老李案例分享:MAT分析应用程序服务出现内存溢出过程1
- 老李案例分享:MAT分析应用程序服务出现内存溢出过程2
- 老李案例分享:定位JAVA内存溢出 1
- 老李案例分享:定位JAVA内存溢出 2
- 性能测试培训: 建立压力模型
- 老李分享:你知道有哪些持续集成工具
- 老李分享知识:性能测试之TPS和吞吐率
- 老李分享知识:性能测试之吞吐量
- 性能测试培训:分析内训泄露的案例
- 自动化测试培训:qtp脚本获取获取汇率数据
- 性能测试培训:sql server性能测试分析局部变量的性能影响1