shell命令总结2
1.cat是一个简单的通用的命令,它可以来显示文本内容,创建文件,还可以显示控制字符# cat test1.txt test2.txt test3.txt//连续查看test1-3的内容
test1
test2
test3
2.管道|
# who //who查看信息
root tty1 2013-03-29 11:19
root pts/0 2013-03-29 14:16 (192.168.22.33)
# who|awk '{print $1 "\t" $2 }'//显示 who的前两列\t是跳格显示
root tty1
root pts/0
# df -h //查看磁盘大小
Filesystem > /dev/hda2 9.7G4.4G4.9G48% /
/dev/hda1 99M 20M 75M21% /boot
tmpfs 227M 0227M 0% /dev/shm
none 227M104K227M 1% /var/lib/xenstored
# df -h|awk '{print $1"\t" $3}'|grep -v "Used"| //查看空间大小利用管道和awk打印第一列和第二列中间利用\t跳格,再次利用管道和grep Used字段。
/dev/hda2 4.4G
/dev/hda1 20M
tmpfs 0
none 104K
3.tee命令当执行脚本或者命令时候想把结果保存起来就要用到tee命令-a参数在末尾添加
# ls -l|tee ls.txt //利用tee创建一个ls.txt文件
total 12
-rw-r--r-- 1 root root 0 Mar 29 14:33 ls.txt
-rw-r--r-- 1 root root 6 Mar 29 14:13 test1.txt
-rw-r--r-- 1 root root 6 Mar 29 14:14 test2.txt
-rw-r--r-- 1 root root 6 Mar 29 14:14 test3.txt
# cat ls.txt //查看ls.txt文件如下
total 12
-rw-r--r-- 1 root root 0 Mar 29 14:33 ls.txt
-rw-r--r-- 1 root root 6 Mar 29 14:13 test1.txt
-rw-r--r-- 1 root root 6 Mar 29 14:14 test2.txt
-rw-r--r-- 1 root root 6 Mar 29 14:14 test3.txt
4. 点.可以匹配任何单字符
# ls -l|grep ...x..x..x //匹配有执行权限的文件
drwxr-xr-x 2 root root4096 May 182012 Desktop
drwxr-xr-x 2 root root4096 Mar 29 14:33 shell
drwxr-xr-x 3 root root4096 Mar 28 10:52 tasks
5.匹配行首^ 以匹配字符串和字符序列
# ll|grep ^d //匹配首行为d目录的文件
drwxr-xr-x 2 root root4096 May 182012 Desktop
drwxr-xr-x 2 root root4096 Mar 29 14:33 shell
drwxr-xr-x 3 root root4096 Mar 28 10:52 tasks
页:
[1]