|
2019-07-09
2019-07-11
从中间20000开始显示到底:
- tail -n +20000 /usr/share/dict/words
复制代码 验证:
- cat -n /usr/share/dict/words | tail -n +20000 | head -n 1
复制代码- [root@desktop3 labs]# wc 124-2.txt
- 3 6 35 124-2.txt
- [root@desktop3 labs]# wc -l 124-2.txt
- 3 124-2.txt
- [root@desktop3 labs]# wc -c 124-2.txt
- 35 124-2.txt
- [root@desktop3 labs]# wc -w 124-2.txt
- 6 124-2.txt
- [root@desktop3 labs]# cat 124-2.txt
- cat
- dog fish
- sheep goat bird
复制代码 ; 连接命令,&也连接命令 -------; 之前的命令是前台命令而&之前的命令是后台命令:
- [root@desktop3 ~]# echo "Hello"; echo "World"
- Hello
- World
- [root@desktop3 ~]# echo -n "Hello"; echo "World"
- HelloWorld
- [root@desktop3 ~]# echo -n "Hello "; echo "World"
- Hello World
- [root@desktop3 ~]#
复制代码- [root@desktop3 ~]# ( sleep 3 ; echo "Hello " ) & echo "World"
- [1] 59835
- World
- [root@desktop3 ~]# Hello
复制代码- [root@desktop3 ~]# sleep 3 ; echo "Hello " & echo "World"
- [1] 59846
- World
- Hello
复制代码
ACCESS TIME/MODIFY TIME/CHANG TIME
- [root@desktop3 labs]# cat <124-2backup.txt
- cat
- dog fish
- sheep goat bird donkey
- [root@desktop3 labs]# stat 124-2backup.txt
- File: ‘124-2backup.txt’
- Size: 42 Blocks: 8 IO Block: 4096 regular file
- Device: fd00h/64768d Inode: 51563253 Links: 1
- Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
- Context: unconfined_u:object_r:admin_home_t:s0
- Access: 2019-07-10 00:16:19.431842205 +0800
- Modify: 2019-07-10 00:15:43.831843306 +0800
- Change: 2019-07-10 00:15:43.831843306 +0800
- Birth: -
- [root@desktop3 labs]# chmod 644 124-2backup.txt
- [root@desktop3 labs]# stat 124-2backup.txt
- File: ‘124-2backup.txt’
- Size: 42 Blocks: 8 IO Block: 4096 regular file
- Device: fd00h/64768d Inode: 51563253 Links: 1
- Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
- Context: unconfined_u:object_r:admin_home_t:s0
- Access: 2019-07-10 00:16:19.431842205 +0800
- Modify: 2019-07-10 00:15:43.831843306 +0800
- Change: 2019-07-10 00:17:00.117840946 +0800
- Birth: -
- [root@desktop3 labs]# echo "tiger" >> 124-2backup.txt
- [root@desktop3 labs]# stat 124-2backup.txt
- File: ‘124-2backup.txt’
- Size: 48 Blocks: 8 IO Block: 4096 regular file
- Device: fd00h/64768d Inode: 51563253 Links: 1
- Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
- Context: unconfined_u:object_r:admin_home_t:s0
- Access: 2019-07-10 00:16:19.431842205 +0800
- Modify: 2019-07-10 00:17:17.003840424 +0800
- Change: 2019-07-10 00:17:17.003840424 +0800
- Birth: -
- [root@desktop3 labs]#
复制代码
总结:以下命令:
[root@desktop3 labs]# ls -l
total 12
-rw-r--r--. 1 root root 48 Jul 10 00:17 124-2backup.txt
-rw-r--r--. 2 root root 35 Jul 9 22:31 124-2itself.txt
-rw-r--r--. 2 root root 35 Jul 9 22:31 124-2.txt
红的部分是从labs这个“文件”里读到的。
其他是分别从这三个文件的内节点(512字节)里读到的。
stat是比ls -l 看得更详细的命令。
----------------------------------------------------------------
- [root@desktop3 labs]# ls
- 124-2backup.txt 124-2.txt
- [root@desktop3 labs]# ln 124-2.txt 124-2itself.txt
- [root@desktop3 labs]# ls -i
- 51563253 124-2backup.txt 51563251 124-2itself.txt 51563251 124-2.txt
- [root@desktop3 labs]# ls -l
- total 12
- -rw-r--r--. 1 root root 48 Jul 10 00:17 124-2backup.txt
- -rw-r--r--. 2 root root 35 Jul 9 22:31 124-2itself.txt
- -rw-r--r--. 2 root root 35 Jul 9 22:31 124-2.txt
- [root@desktop3 labs]# ls
- 124-2backup.txt 124-2itself.txt 124-2.txt
- [root@desktop3 labs]# ln 124-2.txt /etc/
- [root@desktop3 labs]# ln 124-2.txt /boot/
- ln: failed to create hard link ‘/boot/124-2.txt’ => ‘124-2.txt’: Invalid cross-device link
复制代码 -------------------------------------------------------------------文件通配符合命令行扩展:
- find / -name "[[:space:]]*" -o -name ".[[:space:]]*"
复制代码- find / -name "[[:space:]]*"
复制代码 ---------------() [] {}
命令行扩展:
()表示“子shell”:
- [root@desktop3 ~]# ( A=1 ; echo $A ); echo $A
- 1
- [root@desktop3 ~]# A=1 ; echo $A ; echo $A
- 1
- 1
复制代码 ()还表示某个命令的输出(就是变量的值,由于是文本所以自动把回车变空格):
- [root@desktop3 ~]# echo $(ifconfig)
- ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.0.3 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::aee7:413b:9d99:8a55 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:04:76:32 txqueuelen 1000 (Ethernet) RX packets 72019 bytes 21440242 (20.4 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 18734 bytes 5792316 (5.5 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 275 bytes 26112 (25.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 275 bytes 26112 (25.5 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:3f:37:90 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
复制代码
[]带表整型计算的结果:
- [root@desktop3 ~]# echo $[ 1 + 2 ]
- 3
- [root@desktop3 ~]# echo $[ 10 / 2 ]
- 5
- [root@desktop3 ~]# echo $[ 10 / 3 ]
- 3
复制代码 []还代表判断的标准:
- [root@desktop3 ~]# A=0
- [root@desktop3 ~]# [ $A -lt 10 ] && echo "OK"
- OK
- [root@desktop3 ~]# A=10
- [root@desktop3 ~]# [ $A -lt 10 ] && echo "OK"
- [root@desktop3 ~]#
复制代码
{}代表命令的“乘法分配律”:
- [root@desktop3 ~]# echo {A,B}{1,2,3}
- A1 A2 A3 B1 B2 B3
复制代码 {}代表“子程序”:
- [root@desktop3 ~]# SUB1() { echo "Hello"; }
- [root@desktop3 ~]# SUB1
- Hello
复制代码 {}限定变量名:- [root@desktop3 ~]# A=1
- [root@desktop3 ~]# A1=a
- [root@desktop3 ~]# echo $A1
- a
- [root@desktop3 ~]# echo ${A}1
- 11
复制代码
文件通配符:
()没有
[]代表其中的任意一个字符,要记住这些:[[:digit:]]、[[:space:]]这些特殊字符
{}没有
----------------------------------------------------文件通配符,一定能够使用echo测出来; 而命令行扩展就未必(如果能测,也是因为是echo这条命令的命令行扩展):
- [root@desktop3 ~]# echo cd -
- cd -
- [root@desktop3 ~]# echo ~+
- /root
- [root@desktop3 ~]# echo ~-
- /
复制代码 文件通配符:
- [root@desktop3 labs]# touch a1 b1 c1 a2 b2 c2
- [root@desktop3 labs]# echo [abc][12]
- a1 a2 b1 b2 c1 c2
复制代码 命令行扩展:
- [root@desktop3 labs]# echo {a,b,c}{1,2}
复制代码复制代码
|
|