老李分享:《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. xml中的SQL注入

    大家通常知道xml中大部分会导致外部实体注入,但是,xml也会出现SQL注入: 在xml中正常的sql语句写法有两种: 第一: <select id="selectById" ...

  2. 【转】jqGrid学习之安装

    jqGrid安装很简单,只需把相应的css.js文件加入到页面中即可. 按照官网文档: /myproject/css/             ui.jqgrid.css             /u ...

  3. 【转】SQLState详解

    根据 X/Open 和 SQL Access Group SQL CAE 规范 (1992) 所进行的定义,SQLERROR 返回 SQLSTATE 值.SQLSTATE 值是包含五个字符的字符串 . ...

  4. 基于keepalived搭建MySQL高可用集群

    MySQL的高可用方案一般有如下几种: keepalived+双主,MHA,MMM,Heartbeat+DRBD,PXC,Galera Cluster 比较常用的是keepalived+双主,MHA和 ...

  5. Apache2.2以上版本与Tomcat整合配置及负载均衡实现

    apache2.2以上版本,无需使用jk_mod来集成tomcat,直接使用ajp,很方便. 修改apache配置文件httpd.conf 启用mod_proxy_ajp #LoadModule pr ...

  6. git如何解决冲突(代码托管在coding)

    分支A提交合并请求到分支B,有冲突 git fetch code 拉取远程仓库的其他分支代码(我拉代码是remote add code所以这里是code,可以用git remote查看) git ch ...

  7. 在Windows平台搭建轻巧的Python开发环境——面向工程和科研的扩展包配置

    首先,下载最新版本的Python. 为什么强调最新版本呢,因为新版本的漏洞通常会少得多,而且反映了未来的趋势. 既然要学,何不起点高一点? 官方下载地址:https://www.python.org/ ...

  8. 问题 : lang.NoClassDefFoundError: org/springframework/core/annotation/AnnotatedElementUtils,的解决方法

    今天在做junit 测试的时候  出现了一个问题,花了一段时间 才解决. java.lang.NoClassDefFoundError: org/springframework/core/annota ...

  9. RAP在Linux 上的部署

    首先讲一下,rap 是什么东西 ,rap 是一种项目的管理工具.用来管理项目的接口的. 首先是在Linux 上装了一个tomcat8  .当然jdk 的环境是必须要有的, 在rap的官网下载了war包 ...

  10. asp.net core mvc剖析:mvc动作选择

    一个http请求过来后,首先经过路由规则的匹配,找到最符合条件的的IRouter,然后调用IRouter.RouteAsync来设置RouteContext.Handler,最后把请求交给RouteC ...