1.cat命令详解
cat 是concatnate(拼接)的简写.
语法:
cat file1 file2 file3 ....
作用:将文件内容拼接在一起进行输出
具体应用:
1).压缩空白行
加上-s参数压缩连续的空白行
amosli@amosli-pc:~/learn$ cat mutil_blank.txt thisis blank!amosli@amosli-pc:~/learn$ cat -s mutil_blank.txt #压缩连续的空白行thisis blank!
移除所有的空白行,
tr -s "\n"
amosli@amosli-pc:~/learn$ cat mutil_blank.txt | tr -s "\n"thisis blank!
2).将制表符显示为^|
-T 参数
amosli@amosli-pc:~/learn$ cat file.py def function(): var = 5; next = 6; third = 7;amosli@amosli-pc:~/learn$ cat -T file.py # 加上参数-T,即可将制表符标示出来!def function():^Ivar = 5;^I^Inext = 6;^Ithird = 7;
3).显示行号
-n参数
amosli@amosli-pc:~/learn$ cat -n file.py #加上参数-n即可显示行号 1 def function(): 2 var = 5; 3 next = 6; 4 third = 7; 5
2.录制与回放终端会话
amosli@amosli-pc:~/learn$ script -t 2> timing.log -a output.session#开始录制Script started, file is output.sessionamosli@amosli-pc:~/learn$ hello1No command 'hello1' found, did you mean: Command 'hello' from package 'hello-debhelper' (main) Command 'hello' from package 'hello' (main)hello1: command not foundamosli@amosli-pc:~/learn$ whoamosli tty7 2013-12-19 22:58amosli pts/1 2013-12-19 22:59 (:0.0)amosli pts/2 2013-12-19 23:16 (:0.0)amosli@amosli-pc:~/learn$ timereal 0m0.000suser 0m0.000ssys 0m0.000samosli@amosli-pc:~/learn$ date2013年 12月 20日 星期五 01:06:41 CSTamosli@amosli-pc:~/learn$ exitexit #结束录制Script done, file is output.session
播放录制:
amosli@amosli-pc:~/learn$ scriptreplay timing.log output.session #按播放命令序列输出amosli@amosli-pc:~/learn$ hello1No command 'hello1' found, did you mean: Command 'hello' from package 'hello-debhelper' (main) Command 'hello' from package 'hello' (main)hello1: command not foundamosli@amosli-pc:~/learn$ whoamosli tty7 2013-12-19 22:58amosli pts/1 2013-12-19 22:59 (:0.0)amosli pts/2 2013-12-19 23:16 (:0.0)amosli@amosli-pc:~/learn$ timereal 0m0.000suser 0m0.000ssys 0m0.000samosli@amosli-pc:~/learn$ date2013年 12月 20日 星期五 01:06:41 CSTamosli@amosli-pc:~/learn$ exitamosli@amosli-pc:~/learn$
进行多个用户之间进行广播视频会话:打开两个终端
(1)在终端1中输入以下命令:
mkfifo scriptfifo
(2)在终端2中输入以下命令:
cat scriptfifo
(3)返回终端1,输入以下命令:
script -f scriptfifocommands...
这样就实现了广播,在线课堂类的作用,非常神奇!!
我自己实验的输出:
终端1:amosli@amosli-pc:~$ mkfifo scriptfifoamosli@amosli-pc:~$ script -f scriptfifo Script started, file is scriptfifoamosli@amosli-pc:~$ whoamosli tty7 2013-12-19 22:58amosli pts/1 2013-12-19 22:59 (:0.0)amosli pts/2 2013-12-20 01:14 (:0.0)amosli pts/4 2013-12-20 01:16 (:0.0)amosli pts/5 2013-12-20 01:20 (:0.0)amosli pts/6 2013-12-20 01:20 (:0.0)amosli@amosli-pc:~$ 终端2:amosli@amosli-pc:~$ cat scriptfifoScript started on 2013年12月20日 星期五 01时21分19秒amosli@amosli-pc:~$ whoamosli tty7 2013-12-19 22:58amosli pts/1 2013-12-19 22:59 (:0.0)amosli pts/2 2013-12-20 01:14 (:0.0)amosli pts/4 2013-12-20 01:16 (:0.0)amosli pts/5 2013-12-20 01:20 (:0.0)amosli pts/6 2013-12-20 01:20 (:0.0)amosli@amosli-pc:~$