shell的学习入门极难,这我是知道了,想想自己学习shell也差不多半年了,其中总是学学停停,没有一点儿的转眼劲儿,看来是不能将这shell学好了。所以想到这样的一招来督促自己好好学习shell,积少成多:
5月15号下午2点半:
获取当前的ip地址:
ifconfig eth0 |grep "inet addr"|awk '{print $2}' |cut -c 6
[root@fsailing1 ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:21:5E:6A:CE:22
inet addr:10.5.110.239 Bcast:10.5.110.255 Mask:255.255.255.192
inet6 addr: fe80::221:5eff:fe6a:ce22/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:29762157 errors:0 dropped:0 overruns:0 frame:0
TX packets:6640483 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3710301389 (3.4 GiB) TX bytes:2064531172 (1.9 GiB)
Interrupt:177 Memory:91a80000-91aa0000
[root@fsailing1 ~]# ifconfig eth0 |grep "inet addr"
inet addr:10.5.110.239 Bcast:10.5.110.255 Mask:255.255.255.192
[root@fsailing1 ~]# ifconfig eth0 |grep "inet addr"|awk '{print $2}'
addr:10.5.110.239
[root@fsailing1 ~]# ifconfig eth0 |grep "inet addr"|awk '{print $2}'|cut -c 2
d
[root@fsailing1 ~]# ifconfig eth0 |grep "inet addr"|awk '{print $2}'|cut -c 6-
10.5.110.239
5月16号下午3点:
查看当前的所有进程:
ps -A
[root@fsailing1 shell]# ps -A
PID TTY TIME CMD
1 ? 00:00:01 init
2 ? 00:00:00 migration/0
3 ? 00:00:00 ksoftirqd/0
4 ? 00:00:00 watchdog/0
5 ? 00:00:00 migration/1
6 ? 00:00:00 ksoftirqd/1
7 ? 00:00:00 watchdog/1
8 ? 00:00:00 events/0
9 ? 00:00:00 events/1
10 ? 00:00:00 khelper
11 ? 00:00:00 kthread
15 ? 00:00:00 kblockd/0
16 ? 00:00:00 kblockd/1
17 ? 00:00:00 kacpid
120 ? 00:00:00 cqueue/0
查看当前进程打开的文件
lsof -p PID
[root@fsailing1 shell]# lsof -p 1
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
init 1 root cwd DIR 8,6 4096 2 /
init 1 root rtd DIR 8,6 4096 2 /
init 1 root txt REG 8,6 38652 98659 /sbin/init
init 1 root mem REG 8,6 245376 512172 /lib/libsepol.so.1
init 1 root mem REG 8,6 93508 512173 /lib/libselinux.so.1
init 1 root mem REG 8,6 129900 512152 /lib/ld-2.5.so
init 1 root mem REG 8,6 1693812 512156 /lib/libc-2.5.so
init 1 root mem REG 8,6 20668 512164 /lib/libdl-2.5.so
init 1 root 10u FIFO 0,17 1059 /dev/initctl
5月17号下午4点
查看shell脚本的位置:
cat /etc/shells
[root@fsailing1 ~]# cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/bin/tcsh
/bin/csh
/bin/ksh
查看etc/passwd中的shell类型个数
cat /etc/passwd|awk -F: '{print $7}'|sort|uniq -c
[root@fsailing1 ~]# cat /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
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
[root@fsailing1 ~]# cat /etc/passwd|awk '{print $7}'
此处并未查到第7行的值,原因是这里的awk用法不是太熟悉,要知道awk使用时候是有条件限制的,-F就是它的类型选项,这里使用:来分割开
[root@fsailing1 ~]# cat /etc/passwd|awk -F: '{print $7}'
/bin/bash
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/bin/sync
/sbin/shutdown
/sbin/halt
/sbin/nologin
[root@fsailing1 ~]# cat /etc/passwd|awk -F: '{print $7}'|sort
/bin/bash
/bin/bash
/bin/bash
/bin/bash
/bin/bash
/bin/bash
/bin/sync
/sbin/halt
[root@fsailing1 ~]# cat /etc/passwd|awk -F: '{print $7}'|sort|uniq -c
1
6 /bin/bash
1 /bin/sync
1 /sbin/halt
34 /sbin/nologin
1 /sbin/shutdown
5月18号 上午11点 paste的基本用法
[root@fsailing1 shell]# paste --help
用法:paste [选项]... [文件]...
Write lines consisting of the sequentially corresponding lines from
each FILE, separated by TABs, to standard output.
With no FILE, or when FILE is -, read standard input.
长选项必须用的参数在使用短选项时也是必须的。
-d, --delimiters=LIST reuse characters from LIST instead of TABs
-s, --serial paste one file at a time instead of in parallel
--help 显示此帮助信息并退出
--version 输出版本信息并退出
[rocrocket@rocrocket programming]$ paste p3.txt p2.txt p1.txt
I a 1
II b 2
III c 3
[rocrocket@rocrocket programming]$ paste -d '*' p3.txt p2.txt p1.txt
I*a*1
II*b*2
III*c*3
[rocrocket@rocrocket programming]$ paste -s -d "*" p3.txt p2.txt p1.txt
I*II*III
a*b*c
1*2*3