老李分享:《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
done

5、生成符号链接文件
[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 1

fi

path=$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"]}

done

6、实时观看不断增长的文件
[root@localhost touch_more]# tail -f filestat.sh
 
7、目录切换
[root@localhost program_test]# cd -
/home/yxx/program_test/touch_more

老李分享:《Linux Shell脚本攻略》 要点(三)的更多相关文章

  1. 老李分享:《Linux Shell脚本攻略》 要点(八)

    老李分享:<Linux Shell脚本攻略> 要点(八)   1.打印进程 [root@localhost program_test]# ps -e | head  PID TTY     ...

  2. 老李分享:《Linux Shell脚本攻略》 要点(七)

    老李分享:<Linux Shell脚本攻略> 要点(七)   1.显示给定文件夹下的文件的磁盘适用情况 [root@localhost program_test]# du -a -h ./ ...

  3. 老李分享:《Linux Shell脚本攻略》 要点(六)

    老李分享:<Linux Shell脚本攻略> 要点(六)   1.打印网络接口列表 [root@localhost touch_more]# ifconfig | cut -c-10 | ...

  4. 老李分享:《Linux Shell脚本攻略》 要点(五)

    老李分享:<Linux Shell脚本攻略> 要点(五)   //1.打包.解包 [root@localhost program_test]# tar -cf output.tar 11. ...

  5. 老李分享:《Linux Shell脚本攻略》 要点(四)

    老李分享:<Linux Shell脚本攻略> 要点(四)   1.IP地址的正则表达式: [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} 2. ...

  6. 老李分享:《Linux Shell脚本攻略》 要点(二)

    老李分享:<Linux Shell脚本攻略> 要点(二)   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课 ...

  7. 老李分享:《Linux Shell脚本攻略》 要点(一)

    老李分享:<Linux Shell脚本攻略> 要点(一)   第一章:Shell起步基础 1.变量:在bash中,每一个变量的值都是字符串.无论你给变量赋值时,有没有使用引号,值都会以字符 ...

  8. 读《Linux Shell脚本攻略》(第2版) 总结

    前段时间读完了<Linux Shell脚本攻略>(第2版)这本书,给部分想读这本书的人分享下个人感受. 说下这本书的难度吧.纯新手或者只懂少部分编程知识的人,读起来还是有很大难度的.以我为 ...

  9. 读《Linux Shell脚本攻略》(第2版) 一遍、二遍体会

    前段时间读完了<Linux Shell脚本攻略>(第2版)这本书,给部分想读这本书的人分享下个人感受. 第一遍体会解读:就像黑夜中的灯塔,指明前进的道路. 推荐指数:强烈推荐. 书中讲解的 ...

随机推荐

  1. jQuery ajax() 参数,回调函数,数据类型,发送数据到服务器,高级选项

    $.ajax({ options:/*类型:Object;  可选.AJAX 请求设置.所有选项都是可选的.*/ async:/*类型:Boolean; 默认值: true.默认设置下,所有请求均为异 ...

  2. R系列:分词、去停用词、画词云(词云形状可自定义)

    附注:不要问我为什么写这么快,是16年写的. R的优点:免费.界面友好(个人认为没有matlab友好,matlab在我心中就是统计软件中极简主义的代表).小(压缩包就几十M,MATLAB.R2009b ...

  3. MVC和三层架构

    从最开始写程序到现在,一路上听到架构这个词已经无数次了,在工作和圈子里也不停听到大家在讨论它,但是很多时候发现不少人对这个概念的理解都是很模糊的,无意间在知道上看到一个朋友的回答,感觉很不错,特转帖到 ...

  4. 蔡勒(Zeller)公式:根据日期推算是星期几

    Zeller's Congruence: w=y + [y/4] + [c/4] - 2c + [26(m+1)/10] + d - 1 公式中的符号含义如下:w:星期: w对7取模得:0-星期日,1 ...

  5. iOS 图片旋转方法

    iOS 图片旋转方法 通过 CGImage 或 CIImage 旋转特定角度 UIImage可通过CGImage或CIImage初始化,初始化方法分别为init(cgImage: CGImage, s ...

  6. Hibernate框架单向多对一关联映射关系

    建立多对一的单向关联关系    Emp.java            private Integer empNo //员工编号            private String empName / ...

  7. MAC本如何优雅的创建定时任务

    在MACOS上设置定时任务大体有两种方案.一种是使用crontab,一种是使用Schedule,今天结合我的使用简单介绍一下. 先说一下背景,为什么MAC可以用crontab.如果使用过Linux的同 ...

  8. Python入门教程(3)

    人生苦短,我学Pyhton Python(英语发音:/ˈpaɪθən/), 是一种面向对象.解释型计算机程序设计语言,由Guido van Rossum于1989年底发明,第一个公开发行版发行于199 ...

  9. 调试时a标签禁止跳转方法

    a.setAttribute("onclick",'');

  10. AlloyFinger.js 源码 学习笔记及原理说明

    此手势库利用了手机端touchstart, touchmove, touchend, touchcancel原生事件模拟出了 rotate  touchStart  multipointStart   ...