shell - 运算, atime ctime mtime, find使用的时间, wc统计,

运算加减乘除

#! /bin/bash
a=3
b=4
j1=$[a+b]
j2=$((a+b))
s1=$[a*b]
s2=$((a*b))
c1=$((b**a))
c2=$[b**a]
y1=$[b%a]
y2=$((b%a))
echo "3+4=$j1 $j2 3*4=$s1 $s2 4的三次方=$c1 $c2 4除以3余数=$y1 $y2"

[root@second ~]# bash count.sh
3+4=7 7 3*4=12 12 4的三次方=64 64 4除以3余数=1 1

atime是读取时间,创建时间;

  • mtime是修改时间
  • ctime修改过权限,属主,会记录时间,mtime改变同时跟着改变;
#! /bin/bash
date
ping www.baidu.com > ping.txt &
sleep 5
pkill ping
stat ping.txt
sleep 5
cat ping.txt
stat ping.txt

[root@second ~]# bash time.sh
Sat Dec 14 12:21:28 CST 2019
time.sh: line 5: 44623 Terminated              ping www.baidu.com > ping.txt
  File: 'ping.txt'
  Size: 445       	Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d	Inode: 35241291    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-12-14 12:16:37.923196881 +0800
Modify: 2019-12-14 12:21:33.859174445 +0800    #最后修改时间;
Change: 2019-12-14 12:21:33.859174445 +0800    #Ctime跟Mtime一样;
 Birth: -
PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data.
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=128 time=9.04 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=128 time=10.0 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=3 ttl=128 time=9.18 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=4 ttl=128 time=10.1 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=5 ttl=128 time=8.83 ms
  File: 'ping.txt'
  Size: 445       	Blocks: 8          IO Block: 4096   regular file
Device: 803h/2051d	Inode: 35241291    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-12-14 12:21:39.014138859 +0800    #cat命令后, atime改变;
Modify: 2019-12-14 12:21:33.859174445 +0800
Change: 2019-12-14 12:21:33.859174445 +0800
 Birth: -

find使用的时间是以当前时间为截止的

  • 1分钟内算60秒,不会算当前分钟数的前一分钟内所有时间;
  • 同样使用mtime等,一天也是算准的24小时;
#! /bin/bash
touch 00.txt
stat 00.txt
sleep 5
touch 11.txt
stat 11.txt
sleep 59     #59秒内生成了两个文件;
touch 22.txt
stat 22.txt
date
find . -amin -1  #1分钟内只找到两个文件;上面改成sleep 60只会找到22.txt;

[root@second ~]# bash findtime.sh
  File: '00.txt'
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: 803h/2051d	Inode: 35241321    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-12-14 12:39:43.302571581 +0800
Modify: 2019-12-14 12:39:43.302571581 +0800
Change: 2019-12-14 12:39:43.302571581 +0800
 Birth: -
  File: '11.txt'
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: 803h/2051d	Inode: 35241327    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-12-14 12:39:48.310573557 +0800
Modify: 2019-12-14 12:39:48.310573557 +0800
Change: 2019-12-14 12:39:48.310573557 +0800
 Birth: -
  File: '22.txt'
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: 803h/2051d	Inode: 35241328    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-12-14 12:40:47.317928875 +0800
Modify: 2019-12-14 12:40:47.317928875 +0800
Change: 2019-12-14 12:40:47.317928875 +0800
 Birth: -
Sat Dec 14 12:40:47 CST 2019
./11.txt
./22.txt

wc 统计

wc -L 查所有行中最长的行的长度;当只给一行内容时,可查出一行的长度;不算换行符,算上空格;会算tab,一个tab范围算8个字符;符号如?算长度1;
wc -c 查字节个数;跟-m的结果一样;
wc -m 查字符数,包括换行和空格和tab; 符号都算1个字符;
wc -w 统计字数,由空白、跳格或换行字符分隔的字符串;
cat -A 显示tab符和换行符;

[root@second ~]# wc -L wc.txt 
18 wc.txt
[root@second ~]# cat -A wc.txt 
1234 112^Ij?$
[root@second ~]# cat  wc.txt 
1234 112	j?
[root@second ~]# wc -w wc.txt 
3 wc.txt
[root@second ~]# wc -m wc.txt 
12 wc.txt
[root@second ~]# wc -c wc.txt 
12 wc.txt
发布了125 篇原创文章 · 获赞 5 · 访问量 4617

猜你喜欢

转载自blog.csdn.net/tanyyinyu/article/details/103537505