Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1745861
  • 博文数量: 297
  • 博客积分: 285
  • 博客等级: 二等列兵
  • 技术积分: 3006
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-06 22:04
个人简介

Linuxer, ex IBMer. GNU https://hmchzb19.github.io/

文章分类

全部博文(297)

文章存档

2020年(11)

2019年(15)

2018年(43)

2017年(79)

2016年(79)

2015年(58)

2014年(1)

2013年(8)

2012年(3)

分类: LINUX

2016-07-11 14:33:44

1.  使用ls 来查看文件的 mtime,ctime,atime。 注意这里面没有createtime。

点击(此处)折叠或打开

  1. ls -lc filename 列出文件的 ctime change-status times
  2. ls -lu filename 列出文件的 atime last-access times
  3. ls -l filename 列出文件的 mtime 文件属性(比如权限)修改的时间,一般mtime改变时ctime也会改变。 last-modification times
  4. ls -lt |head -n 10         #先根据mtime 排序,然后查看最新创建的10个文件名
2.  touch 命令来修改mtime,atime. 

点击(此处)折叠或打开

  1. touch -m -t 08010600 chi.txt    #修改mtime 为Aug 1 ,mtime 可以修改到将来
  2. touch -a -t 06232230 chi.txt    #修改atime 
  3. touch -t 201607100000 aa.txt
  4. touch -t 201607110000 bb.txt    #我们创建了两个文件 aa.txt 的mtime 和 atime 都是 我们制定的,但是ctime 仍然是系统默认的
  5. ls -lt aa.txt 
    -rw-r--r-- 1 root root 0 Jul 10 00:00 aa.txt    #mtime
  6. ls -lu aa.txt 
    -rw-r--r-- 1 root root 0 Jul 10 00:00 aa.txt    #atime
  7. ls -lc aa.txt 
    -rw-r--r-- 1 root root 0 Jul 11 12:56 aa.txt    #ctime 
3. 如何找出一天内创建的文件.
使用上面创建的文件我们可以找出 在 20160710号这一天在当前目录下创建的文件。

点击(此处)折叠或打开

  1. find ./ -type f -newer aa.txt ! -newer bb.txt
4. 为什么这个find 命令没有输出? 因为/usr/share/zoneinfo/posix/ 目录下都是软连接

点击(此处)折叠或打开

  1. find /usr/share/zoneinfo/posix/ -type f
  2. file /usr/share/zoneinfo/posix/Cuba
  3. /usr/share/zoneinfo/posix/Cuba: symbolic link to ../Cuba
  4. #如果要follow 软连接,需要加上find -L
  5. find -L /usr/share/zoneinfo/posix/ -type f 
5. 重定向stderr,stdout, 使得我的脚本输出能同时出现在屏幕和文件中.

点击(此处)折叠或打开

  1. printf '%s\n%v\n' OK? 2>&1 |tee logs        #tee 默认只复制stdout.
  2. printf '%s\n%v\n' OK? Oops! &>> FILE        #这两种用法不是那么formal,但是都是将stderr 和stdout 重定向到文件 
  3. printf '%s\n%v\n' OK? Oops! &> FILE
6. awk的几个用法
打印最长一行的字符数,当然也可以同时打印出这一行

点击(此处)折叠或打开

  1. awk '{if(length($0)>max) max=length($0)} END {print max}'
  2. awk '{if(length($0)>max) max=length($0)} END {print max,$0}'
打印超过80个字符的行

点击(此处)折叠或打开

  1. awk '{if (length($0)>80) print $0}'
打印最后一行(打印第一行可不是BEGIN)

点击(此处)折叠或打开

  1. awk 'END {print $0}'
打印第一行

点击(此处)折叠或打开

  1. awk 'NR==1 {print $0}'
打印多行

点击(此处)折叠或打开

  1. awk 'NR==3,NR==5 {print NR,$0}'        #3,4,5行
  2. awk 'NR==3 || NR==5 {print NR,$0}'     #3行和5行
  3. awk 'NR<3 || NR>5 {print NR,$0}'       #小于3行,或者大于5行的
打印列数,和每行最后一列

点击(此处)折叠或打开

  1. awk '{print NF,$NF}'
更多awk 的用法,请参阅:








阅读(1173) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~