ABI:
描述了应用程序与OS之间的底层接口,允许编译好的目标代码
在使用兼容ABI的系统中无需改动就能运行
应用程序与操作系统的连接接口
不同的操作系统 接口是不一样的
比如你windows里的软件拷到手机上就不能运行
苹果手机上的软件放到安桌上也不能运行
API:
定义了源代码和库之间的接口,因此同样的源代码可以在支持
这个API的任何系统中编译
以后开发 比如要开发软件 从头开始做 会浪费时间
许多语言都有模块可以拿来用 也就是库 调用就行了
类似不用重复的制造轮子,造车时直接用就行了
当然调用时,要按照接口标准来调用 也就是API
IEEE在操作系统中定义了一系列API标准
POSIX兼容的程序可在其它POSIX操作系统编译执行
windows 命令行下:
convert E:/fs:ntfs
修改分区文件系统
显示、修改时区:
[root@panqi-7 ~]#timedatectl status
Local time: Thu 2018-06-21 20:43:08 CST
Universal time: Thu 2018-06-21 12:43:08 UTC
RTC time: Thu 2018-06-21 12:43:07
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: no
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
[root@panqi-7 ~]#timedatectl set-timezone Europe/Busingen
[root@panqi-7 ~]#timedatectl status
Local time: Thu 2018-06-21 14:43:49 CEST
Universal time: Thu 2018-06-21 12:43:49 UTC
RTC time: Thu 2018-06-21 12:43:48
Time zone: Europe/Busingen (CEST, +0200)
模拟/boot下inode号写满:
[root@panqi-7 ~]#df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda2 4882432 120687 4761745 3% /
devtmpfs 181196 394 180802 1% /dev
tmpfs 184869 1 184868 1% /dev/shm
tmpfs 184869 583 184286 1% /run
tmpfs 184869 16 184853 1% /sys/fs/cgroup
/dev/sda3 4882432 3 4882429 1% /data
/dev/sda1 256000 327 255673 1% /boot
tmpfs 184869 6 184863 1% /run/user/42
tmpfs 184869 16 184853 1% /run/user/0
/dev/sr0 0 0 0 - /run/media/root/CentOS 7 x86_64
[root@panqi-7 ~]#cd /boot/
[root@panqi-7 boot]#mkdir test
[root@panqi-7 boot]#cd test/
[root@panqi-7 test]#touch file{1..256003}
touch: cannot touch ‘file255913’: No space left on device
[root@panqi-7 test]#df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 9754624 3749336 6005288 39% /
devtmpfs 724784 0 724784 0% /dev
tmpfs 739476 0 739476 0% /dev/shm
tmpfs 739476 9240 730236 2% /run
tmpfs 739476 0 739476 0% /sys/fs/cgroup
/dev/sda3 9754624 32944 9721680 1% /data
/dev/sda1 508580 291364 217216 58% /boot 但查看磁盘,并没有满
/dev/sda1 508580 291364 217216 58% /boot 但查看磁盘,并没有满
[root@panqi-7 boot]#df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda2 4882432 120687 4761745 3% /
devtmpfs 181196 394 180802 1% /dev
tmpfs 184869 1 184868 1% /dev/shm
tmpfs 184869 583 184286 1% /run
tmpfs 184869 16 184853 1% /sys/fs/cgroup
/dev/sda3 4882432 3 4882429 1% /data
/dev/sda1 256000 256000 0 100% /boot 原因就是inode号满了
/dev/sda1 256000 256000 0 100% /boot 原因就是inode号满了
PS:如果一个大文件正在使用中,删除该文件并不会释放空间,正确做法:> file
PS:软链接 要写绝对路径
硬链接和软链接区别:
根本区别:
硬链接本质是一个文件,多个名字
软链接本质是多个不同文件
1、跨分区
2、inode number
3、链接数
4、目录
5、删除
修改CentOS7 网卡名
还有一种方法,改模板文件:
/etc/default/grub
然后生成文件,并替换方法一的那个文件
grub-mkconfig -o /boot/grub2/grub.cfg
[root@panqi-7 test]#vim /etc/ntp.conf
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server ntpdate ntp1.aliyun.com iburst
重启服务(6和7方式不同):
panqi:$6$Vbgojhru$LbRZtl8wf7WYv2WSPXZyhG5.LtWWi1VA8JwRVC1cWqkw8I5TSFk.tYyN9aEBLm3kiXp3LWE.g4LdwCJR3rGRw.:17713:0:99999:7:::
:$6$Vbgojhru$LbRZtl8wf7WYv2WSPXZyhG5.LtWWi1VA8JwRVC1cWqkw8I5TSFk.tYyN9aEBLm3kiXp3LWE.g4LdwCJR3rGRw.:17713:0:99999:7:::
[root@panqi-7 ~]#usermod -Ga testgroup panqi -a要在前面
usermod: group 'a' does not exist
[root@panqi-7 ~]#usermod -aG testgroup panqi
[root@panqi-7 ~]#id panqi
uid=1000(panqi) gid=1000(panqi) groups=1000(panqi),1001(testgroup)
[root@panqi-7 ~]#usermod -aG testgroup panqi
[root@panqi-7 ~]#id panqi
uid=1000(panqi) gid=1000(panqi) groups=1000(panqi),1001(testgroup)
[root@panqi-7 ~]#usermod -L panqi
The server has disconnected with an error. Server message reads: A protocol error occurred. Change of username or service not allowed: (root,ssh-connection) -> (panqi,ssh-connection)
如果参数是:+X
那么操作的是目录的话,就对目录加x权限,文件不加x权限
[root@panqi-7 tmp]#ll
total 816
-rwxr-xr-x. 1 root root 0 Jul 1 10:11 1.txt
-rw-r--r--. 1 root root 0 Jul 1 10:11 2.txt
[root@panqi-7 tmp]#chmod 2.txt --reference=1.txt
[root@panqi-7 tmp]#ll
total 816
-rwxr-xr-x. 1 root root 0 Jul 1 10:11 1.txt
-rwxr-xr-x. 1 root root 0 Jul 1 10:11 2.txt
umask 掩码
666
023
110110110 666
000010011 023
110100100
644
default=666/777-umask
只有一种情况
对文件,用666减umask结果如果有奇数,加1
SUID
1、程序要有执行权限(可执行的二进制程序)
2、属主要是root
3、有suid权限
用户使用者,就是临时切换成属主的身份运行
[root@panqi-7 data]#ll /bin/nano
-rwxr-xr-x. 1 root root 205904 Jun 10 2014 /bin/nano
[root@panqi-7 data]#chmod o-r test.sh
[root@panqi-7 data]#ll
total 4
-rwxr-----. 1 root root 24 Jul 1 11:00 test.sh
[root@panqi-7 data]#chmod u+s /bin/nano
[root@panqi-7 data]#ll /bin/nano
-rwsr-xr-x. 1 root root 205904 Jun 10 2014 /bin/nano
---. 1 root root 24 Jul 1 11:00 test.sh
[root@panqi-7 data]#chmod u+s /bin/nano
[root@panqi-7 data]#ll /bin/nano
-rwsr-xr-x. 1 root root 205904 Jun 10 2014 /bin/nano
nano [ Error reading test.sh: Permission denied ] 一开始看不了(用其他用户)
[panqi@panqi-7 data]$nano test.sh
GNU nano 2.3.1 File: test.sh
#!/bin/bash
panqi@panqi-7 data]$nano test.sh
GNU nano 2.3.1 File: test.sh
#!/bin/bash
echo haha! 现在可以了,因为加了sgid权限
SGID
程序要有执行权限(可执行的二进制程序)
启动为进程后,其进程的属组为原程序文件的属组
而且,对此目录有写权限的用户在此目录中创建的文件所属的组为此目录的属组
[panqi@panqi-7 testdir]$chmod g+s .
[panqi@panqi-7 testdir]$ll -d .
drwxr-srwx. 2 panqi panqi 32 Jul 1 11:29 .
[usertest1@panqi-7 testdir]$touch file.txt
[usertest1@panqi-7 testdir]$ll
total 0
-rw-rw-r--. 1 panqi panqi 0 Jul 1 11:20 3.txt
-rw-rw-r--. 1 usertest1 panqi 0 Jul 1 11:36 file.txt usertest1用户创建的文件,属组为panqi
usertest1@panqi-7 testdir]$ll
total 0
-rw-rw-r--. 1 panqi panqi 0 Jul 1 11:20 3.txt
-rw-rw-r--. 1 usertest1 panqi 0 Jul 1 11:36 file.txt usertest1用户创建的文件,属组为panqi
Sticky位
[root@panqi-7 testdir]#ll -d .
drwxr-xrwx. 2 root root 32 Jul 1 11:22 .
[usertest1@panqi-7 testdir]$ll
total 0
-rw-rw-r--. 1 panqi panqi 0 Jul 1 11:20 1.txt
-rw-rw-r--. 1 usertest1 usertest1 0 Jul 1 11:28 2.txt
-rw-rw-r--. 1 panqi panqi 0 Jul 1 11:20 3.txt
-rw-rw-r--. 1 usertest1 usertest1 0 Jul 1 11:28 4.txt
[usertest1@panqi-7 testdir]$rm -f 1.txt 能删
usertest1@panqi-7 testdir]$ll
total 0
-rw-rw-r--. 1 panqi panqi 0 Jul 1 11:20 1.txt
-rw-rw-r--. 1 usertest1 usertest1 0 Jul 1 11:28 2.txt
-rw-rw-r--. 1 panqi panqi 0 Jul 1 11:20 3.txt
-rw-rw-r--. 1 usertest1 usertest1 0 Jul 1 11:28 4.txt
[usertest1@panqi-7 testdir]$rm -f 1.txt 能删
[root@panqi-7 testdir]#chmod o+t .
[root@panqi-7 testdir]#ll -d .
drwxr-xrwt. 2 root root 32 Jul 1 11:29
[usertest1@panqi-7 testdir]$rm -f 3.txt
rm: cannot remove ‘3.txt’: Operation not permitted 不能删了
rm: cannot remove ‘3.txt’: Operation not permitted 不能删了
ACL
前提分区得有ACL功能
[root@panqi-6 ~]#tune2fs -l /dev/sda1
tune2fs 1.41.12 (17-May-2010)
Default mount options: user_xattr acl
acl
[usertest1@panqi-7 testdir]$setfacl -m u:panqi:- /testdir/4.txt
[usertest1@panqi-7 testdir]$setfacl -m u:panqi:- /testdir/file.txt
[panqi@panqi-7 testdir]$cat 4.txt
321
[panqi@panqi-7 testdir]$cat 4.txt
cat: 4.txt: Permission denied
[panqi@panqi-7 testdir]$cat file.txt
cat: file.txt: Permission denied
cat: 4.txt: Permission denied
[panqi@panqi-7 testdir]$cat file.txt
cat: file.txt: Permission denied
[usertest1@panqi-7 testdir]$setfacl -x u:panqi /testdir/file.txt 删除一条
[usertest1@panqi-7 testdir]$setfacl -b /testdir/file.txt 全部清掉
cut命令
[usertest1@panqi-7 testdir]$cut -d o -f1 4.txt
a
1
[usertest1@panqi-7 testdir]$cut -d o -f2 4.txt
b
2
[usertest1@panqi-7 testdir]$cut -c1 4.txt
a
1
[usertest1@panqi-7 testdir]$cat 4.txt
aob
1o2
[root@panqi-7 testdir]#cut -c1,3 --output-delimiter='/' 4.txt
a/b
1/2
[root@panqi-7 testdir]#paste 4.txt file.txt
aoboc 123
1o2o3 456
789
[root@panqi-7 testdir]#paste -d "/" 4.txt file.txt
aoboc/123
1o2o3/456
/789
[root@panqi-7 testdir]#paste -s 4.txt file.txt
aoboc 1o2o3
123 456 789
[root@panqi-7 testdir]#vim 4.txt
aoboc
1o2o3
1o2o3
1o2o3
1o2o3
biubiu
[root@panqi-7 testdir]#sort -u 4.txt
1o2o3
aoboc
biubiu
[root@panqi-7 testdir]#uniq -c 4.txt
1 aoboc
4 1o2o3
1 biubiu
[root@panqi-7 testdir]#uniq -d 4.txt
1o2o3
[root@panqi-7 testdir]#uniq -u 4.txt
aoboc
biubiu
ps:各几行有重复行,找不到
所以一般都是sort先排序,再筛选
[root@panqi-7 testdir]#grep root /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@panqi-7 testdir]#echo $USER
root
[root@panqi-7 testdir]#grep $USER /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@panqi-7 testdir]#grep "$USER" /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@panqi-7 testdir]#grep '$USER' /etc/passwd
[root@panqi-7 testdir]#grep `$USER` /etc/passwd
bash: root: command not found...
[root@panqi-7 testdir]#grep `whoami` /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
root /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@panqi-7 testdir]#echo $USER
root
[root@panqi-7 testdir]#grep $USER /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@panqi-7 testdir]#grep "$USER" /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@panqi-7 testdir]#grep '$USER' /etc/passwd
[root@panqi-7 testdir]#grep `$USER` /etc/passwd
bash: root: command not found...
[root@panqi-7 testdir]#grep `whoami` /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@panqi-7 testdir]#grep -vnc `whoami` /etc/passwd
41
[root@panqi-7 testdir]#grep -e root -e panqi /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
panqi:x:1000:1000:panqi:/home/panqi:/bin/bash
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
panqi:x:1000:1000:panqi:/home/panqi:/bin/bash
[root@panqi-7 testdir]#grep -A3 root /etc/passwd
root:x:0:0:root:/root:/bin/bash 往下三行
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
--
operator:x:11:0:operator:/root:/sbin/nologin 往下三行
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
[root@panqi-7 testdir]#grep -w ro /etc/passwd 匹配整个单词 所以找不到
root:x:0:0:root:/root:/bin/bash 往下三行
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
--
operator:x:11:0:operator:/root:/sbin/nologin 往下三行
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
[root@panqi-7 testdir]#grep -w ro /etc/passwd 匹配整个单词 所以找不到
元字符分类:字符匹配、匹配次数、分组、位置锚定
tr命令
-c或——complerment:取代所有不属于第一字符集的字符;
-d或——delete:删除所有属于第一字符集的字符;
-s或--squeeze-repeats:把连续重复的字符以单独一个字符表示;
-t或--truncate-set1:先删除第一字符集较第二字符集多出的字符。
[root@panqi-7 testdir]#cat 4.txt | tr -d -c '0-9 \n'
123
123
123
123
[root@panqi-7 testdir]#cat 4.txt | tr -d '3'
aoboc
1o2o
1o2o
1o2o
1o2o
biubiu
[root@panqi-7 testdir]#vim 4.txt
aoboc
1o2222222o3
1o2o33333
1o2o3
11111o2o3
biubiu
1o2222222o3
1o2o33333
1o2o3
11111o2o3
biubiu
[root@panqi-7 testdir]#cat 4.txt | tr -s '2'
aoboc
1o2o3
1o2o33333
1o2o3
11111o2o3
biubiu
1o2o3
1o2o33333
1o2o3
11111o2o3
biubiu
[root@panqi-7 testdir]#cat 4.txt | tr -s '123' 也可以一下压缩许多字符
aoboc
1o2o3
1o2o3
1o2o3
1o2o3
biubiu
[root@panqi-7 testdir]#df -h | tr -s " " | cut -d " " -f 5 取磁盘利用率
Use%
43%
0%
0%
2%
0%
1%
31%
1%
1%
100%
0%
[root@panqi-7 testdir]#ifconfig | head -2 | tail -1 | tr -s " " | cut -d " " -f3 取IP
192.168.0.113
[root@panqi-7 testdir]#seq 55 | sort -R | head -1 取随机数1-55之间
[root@panqi-7 testdir]#ifconfig | egrep -o "([0-9]{1,3}\.){3}[0-9]{1,3}" 取所有IP形式地址
([0-9]{1,3}\.){3}[0-9]{1,3}" 取所有IP形式地址
0-9至少一次,最多三次 转意 . 出现三次 再匹配0-9出现至少一次,最多三次
[root@panqi-7 ~]#df -h | grep "^/dev/sd*" | tr -s " " | cut -d " " -f5
[root@panqi-7 ~]#df -h | grep "^/dev/sd*" | egrep -o "[[:digit:]]+%"
取磁盘利用率
[root@panqi-6 Packages]#ll *.rpm | egrep -o "([[:alnum:]_])+.rpm$" | cut -d. -f1 | sort | uniq -c
4 i686
925 noarch
2311 x86_64
[root@panqi-6 Packages]#ls *.rpm | egrep -o "\.[^.]+\.rpm" | cut -d . -f2 | sort | uniq -c
4 i686
925 noarch
2311 x86_64
取光盘里rpm包的类型数量
vim的环境设定参数,想要知道目前的设定值,可以在一般模式时输入【 :set all】来查阅,
:set all "显示目前所有的环境参数设定值
:set hlsearch "高亮度反白(高亮度搜寻)
:set nohlsearch "取消高亮度反白(高亮度搜寻)
:set backspace=2 "在编辑的时候可随时用退格键删除 (0、1的时候,只针对刚输入的字符有效)
:set autoindent "自动缩排
:set noautoindent "取消自动缩排
:set ruler "可显示最后一行的状态
:set showmode "左下角那一行的状态
:set nu "显示行号
:set nonu "取消行号
:set bg=dark "显示不同的底×××调
:syntax on "进行语法检验,颜色显示
:syntax off "关闭语法检验
[root@panqi-6 tmp]#sed '1~2s@[[:lower:]]@&666@g' /tmp/test.txt
a666
b
c666
d
&666@g' /tmp/test.txt
a666
b
c666
d
[root@panqi-6 tmp]#sed -i.bak 's/c/C/g' /tmp/test.txt
[root@panqi-6 tmp]#cat test.txt
a
b
C
d
[root@panqi-6 tmp]#cat test.txt.bak
a
b
c
d
[root@panqi-6 tmp]#sed -n 'n;p' /tmp/test1.txt
2
4
6
[root@panqi-6 tmp]#sed '1!G;h;$!d' /tmp/test1.txt
6
5
4
3
2
1 倒序显示
sed 's/quiet/& net.ifnames=0/' /etc/default/grub
sed '/GRUB_CMDLINE_LINUX/s/"$/ net.ifnames=0 &/' /etc/default/grub
sed -r '/GRUB_CMDLINE_LINUX/s/(.*)"/\1 net.ifnames=0"/' /etc/default/grub
修改CentOS7 网卡名称
[root@panqi-6 tmp]#awk -F : '$0 ~ /root/{print $1}' /etc/passwd
root
operator
[root@panqi-6 tmp]#awk -F : '$3 == 0' /etc/passwd
root:x:0:0:root:/root:/bin/bash
[root@panqi-6 tmp]#awk -F : '$3 == 0{print $1}' /etc/passwd
root
[root@panqi-6 tmp]#awk -F: '{$3>=1000?usertype="Common User":usertype="Sysadmin or SysUser";printf "%15s:%-s\n",$1,usertype}' /etc/passwd
root:Sysadmin or SysUser
bin:Sysadmin or SysUser
daemon:Sysadmin or SysUser
[root@panqi-6 tmp]#awk -F : 'BEGIN {print "USER USERID"}{print $1":"$3}END{print "end file"}' /etc/passwd
USER USERID
root:0
bin:1
daemon:2
adm:3
lp:4
sync:5
shutdown:6
halt:7
mail:8
tcpdump:72
panqi:500
end file
BEGIN {print "USER USERID"}{print $1":"$3}END{print "end file"}' /etc/passwd
USER USERID
root:0
bin:1
daemon:2
adm:3
lp:4
sync:5
shutdown:6
halt:7
mail:8
tcpdump:72
panqi:500
end file
[root@panqi-6 tmp]#awk -F : '{print "USER USERID";print $1":"$3}END{print "end file"}' /etc/passwd
USER USERID
root:0
USER USERID
bin:1
USER USERID
haldaemon:68
panqi:500
end file
USER USERID
root:0
USER USERID
bin:1
USER USERID
haldaemon:68
panqi:500
end file
[root@panqi-6 tmp]#awk -F: 'BEGIN{print "USER UID \n--------------- "}{print$1,$3}' /etc/passwd
USER UID
---------------
root 0
bin 1
daemon 2
USER UID
---------------
root 0
bin 1
daemon 2
[root@panqi-6 tmp]#seq 10 |awk 'i=0'
[root@panqi-6 tmp]#seq 10 |awk 'i=1'
1
2
3
4
5
6
7
8
9
10
[root@panqi-6 tmp]#seq 10 |awk 'i=!i'
1
3
5
7
9 一开始i没有值(假) 结果取反就有值了(真) 第一行显示 第二行时i为真,取反为假,不显示 如下显示:
[root@panqi-6 tmp]#seq 10 | awk '{i=!i;print i}'
1
0
1
0
1
0
1
0
1
0
[root@panqi-6 tmp]#seq 10 | awk '!(i=!i)'
2
4
6
8
10 而这个,在上面结果上再取反 就是第一为假 第二行为真
[root@panqi-6 tmp]#seq 10 |awk -v i=1 'i=!i'
2
4
6
8
10 与上面一样
[root@panqi-6 tmp]#df -h|awk -F% '/^\/dev/{print $1}'|awk '{if($NF>=80)print $1,$5}'
/dev/sr0 100
[root@panqi-6 tmp]#df -h|awk -F% '/^\/dev/{print $1}'|awk '$NF>=80{print $1,$5}'
/dev/sr0 100
[root@panqi-6 tmp]#awk 'BEGIN{test=100;if(test>90){print "very good"}else if(test>60){ print "good"}else{print "no pass"}}'
very good
[root@panqi-6 tmp]#awk 'BEGIN{test=89;if(test>90){print "very good"}else if(test>60){ print "good"}else{print "no pass"}}'
good
[root@panqi-6 tmp]#awk 'BEGIN{test=59;if(test>90){print "very good"}else if(test>60){ print "good"}else{print "no pass"}}'
no pass
i++
i=i+1
i+=10
i=i+10
[root@panqi-7 ~]#awk '/^[[:space:]]*linux16/{i=1;while(i<=NF)
> {print $i,length($i); i++}}' /etc/grub2.cfg
linux16 7
/vmlinuz-3.10.0-693.el7.x86_64 30
root=UUID=5a518a47-3c1b-4d8b-8f89-1cd7be13a890 46
ro 2
rhgb 4
quiet 5
LANG=en_US.UTF-8 16
net.ifnames=0 13
linux16 7
/vmlinuz-0-rescue-8c457ac09c924df28963fe8d910f52a5 50
root=UUID=5a518a47-3c1b-4d8b-8f89-1cd7be13a890 46
ro 2
rhgb 4
quiet 5
[root@panqi-7 ~]#awk '/^[[:space:]]*linux16/{i=1;while(i<=NF){if(length($i)>=10){print $i,length($i)}; i++}}' /etc/grub2.cfg
/vmlinuz-3.10.0-693.el7.x86_64 30
root=UUID=5a518a47-3c1b-4d8b-8f89-1cd7be13a890 46
LANG=en_US.UTF-8 16
net.ifnames=0 13
/vmlinuz-0-rescue-8c457ac09c924df28963fe8d910f52a5 50
root=UUID=5a518a47-3c1b-4d8b-8f89-1cd7be13a890 46
linux16 7
/vmlinuz-3.10.0-693.el7.x86_64 30
root=UUID=5a518a47-3c1b-4d8b-8f89-1cd7be13a890 46
ro 2
rhgb 4
quiet 5
LANG=en_US.UTF-8 16
net.ifnames=0 13
linux16 7
/vmlinuz-0-rescue-8c457ac09c924df28963fe8d910f52a5 50
root=UUID=5a518a47-3c1b-4d8b-8f89-1cd7be13a890 46
ro 2
rhgb 4
quiet 5
[root@panqi-7 ~]#awk '/^[[:space:]]*linux16/{i=1;while(i<=NF){if(length($i)>=10){print $i,length($i)}; i++}}' /etc/grub2.cfg
/vmlinuz-3.10.0-693.el7.x86_64 30
root=UUID=5a518a47-3c1b-4d8b-8f89-1cd7be13a890 46
LANG=en_US.UTF-8 16
net.ifnames=0 13
/vmlinuz-0-rescue-8c457ac09c924df28963fe8d910f52a5 50
root=UUID=5a518a47-3c1b-4d8b-8f89-1cd7be13a890 46
[root@panqi-7 ~]#awk 'BEGIN{ total=0;i=0;do{ total+=i;i++;}while(i<=100);print total}'
5050
[root@panqi-7 ~]#awk 'BEGIN{sum=0;for(i=1;i<=100;i++){sum+=i};print sum}'
5050
[root@panqi-7 ~]#awk 'BEGIN{sum=0;i=1;while(i<=100){sum+=i;i++};print sum}'
5050
[root@panqi-7 ~]#awk -F: '{if($3%2!=0) next; print $1,$3}' /etc/passwd
root 0
daemon 2
lp 4
shutdown 6 1\3\5行
[root@panqi-7 ~]#awk 'BEGIN{weekdays["mon"]="Monday";weekdays["tue"]="Tuesday";for(i in weekdays){print i,weekdays[i]}}'
tue Tuesday
mon Monday
[root@panqi-7 ~]#netstat -tan | awk '/^tcp/{state[$NF]++}END{for(i in state) { print i,state[i]}}'
LISTEN 9
ESTABLISHED 1
[root@panqi-7 ~]#echo "2008:08:08 08:08:08" | awk 'sub(/:/,"-",$1)'
2008-08:08 08:08:08
[root@panqi-7 ~]#echo "2008:08:08 08:08:08" | awk 'gsub(/:/,"-",$1)'
2008-08-08 08:08:08
[root@panqi-7 ~]#echo "2008:08:08 08:08:08" | awk 'gsub(/:/,"-",$0)'
2008-08-08 08-08-08
[root@panqi-6 ~]#who | tee -a who.out | grep root
root tty1 2018-07-06 21:27 (:0)
root pts/2 2018-07-06 21:50 (192.168.1.104)
[root@panqi-6 ~]#cat who.out
root tty1 2018-07-06 21:27 (:0)
root pts/2 2018-07-06 21:50 (192.168.1.104)
read -p "please enter your age: " Age
[[ $Age =~ ^[0-9]+$ ]] || { echo "your age is false"; exit 7; }
if [ "$Age" -ge 0 -a "$Age" -le 18 ];then
echo "very younger!"
elif [ "$Age" -gt 18 -a "$Age" -le 50 ];then
echo "work hard!"
elif [ "$Age" -gt 50 -a "$Age" -le 80 ];then
echo "enjoy your life!"
elif [ "$Age" -gt 80 -a "$Age" -le 120 ];then
echo "very good!"
else
echo "you are ET!"
fi
~
[root@panqi-6 ~]#bash age.sh
please enter your age: 0
very younger!
[root@panqi-6 ~]#bash age.sh
please enter your age: p0
your age is false
[root@panqi-6 ~]#bash age.sh
please enter your age: 89o
your age is false
[root@panqi-6 ~]#bash age.sh
please enter your age: 50
work hard!
while true
do
Num=`df -h | grep "^/dev/sd" | awk '{print $5}' | sed 's@%@@g'`
for i in $Num
do
if [ $i -gt 80 ];then
echo -e "\a"
else
echo "good!"
fi
done
sleep 30
done 查看磁盘是否超出百分比
#!/bin/bash
for i in {1..100};
do
let sum+=$i
done
echo $sum
i=0
while [ $i -le 100 ];
do
let sum+=$i
let i+=1
done
echo $sum
i=0
until [ $i -gt 100 ];
do
let sum+=$i
let i+=1
done
echo $sum
for ((i=0;i<=100;i++));
do
let sum+=$i
done
echo $sum
[root@panqi-6 ~]#source /etc/init.d/functions
[root@panqi-6 ~]#action OK
OK [ OK ]
[root@panqi-6 ~]#action wrong /bin/false
wrong
[root@panqi-6 ~]#Var=haha
[root@panqi-6 ~]#echo $Var
haha
[root@panqi-6 ~]#dir(){ Var=hehe;echo $Var; }
[root@panqi-6 ~]#dir
hehe
[root@panqi-6 ~]#echo $Var
hehe
[root@panqi-6 ~]#Var=haha
[root@panqi-6 ~]#echo $Var
haha
[root@panqi-6 ~]#dir(){ local Var=hehe;echo $Var; }
[root@panqi-6 ~]#dir
hehe
[root@panqi-6 ~]#echo $Var
haha
local Var=hehe;echo $Var; }
[root@panqi-6 ~]#dir
hehe
[root@panqi-6 ~]#echo $Var
haha