1.cat命令详解

cat 是concatnate(拼接)的简写.

语法:

cat file1 file2 file3 ....

作用:将文件内容拼接在一起进行输出

具体应用:

1).压缩空白行

加上-s参数压缩连续的空白行

amosli@amosli-pc:~/learn$ cat mutil_blank.txt
this is blank!
amosli@amosli-pc:~/learn$ cat -s mutil_blank.txt #压缩连续的空白行
this is blank!

移除所有的空白行,

tr -s "\n"
amosli@amosli-pc:~/learn$ cat mutil_blank.txt | tr -s "\n"
this
is
blank!

2).将制表符显示为^|

-T 参数

amosli@amosli-pc:~/learn$ cat file.py
def function():
var = ;
next = ;
third = ; amosli@amosli-pc:~/learn$ cat -T file.py # 加上参数-T,即可将制表符标示出来!
def function():
^Ivar = ;
^I^Inext = ;
^Ithird = ;

3).显示行号

-n参数

amosli@amosli-pc:~/learn$ cat -n file.py #加上参数-n即可显示行号
def function():
var = ;
next = ;
third = ;

2.录制与回放终端会话

amosli@amosli-pc:~/learn$ script -t > timing.log -a output.session#开始录制
Script started, file is output.session
amosli@amosli-pc:~/learn$ hello1
No command 'hello1' found, did you mean:
Command 'hello' from package 'hello-debhelper' (main)
Command 'hello' from package 'hello' (main)
hello1: command not found
amosli@amosli-pc:~/learn$ who
amosli tty7 -- :
amosli pts/ -- : (:0.0)
amosli pts/ -- : (:0.0)
amosli@amosli-pc:~/learn$ time real 0m0.000s
user 0m0.000s
sys 0m0.000s
amosli@amosli-pc:~/learn$ date
2013年 12月 20日 星期五 :: CST
amosli@amosli-pc:~/learn$ exit
exit #结束录制
Script done, file is output.session

播放录制:

amosli@amosli-pc:~/learn$ scriptreplay timing.log output.session #按播放命令序列输出
amosli@amosli-pc:~/learn$ hello1
No command 'hello1' found, did you mean:
Command 'hello' from package 'hello-debhelper' (main)
Command 'hello' from package 'hello' (main)
hello1: command not found
amosli@amosli-pc:~/learn$ who
amosli tty7 -- :
amosli pts/ -- : (:0.0)
amosli pts/ -- : (:0.0)
amosli@amosli-pc:~/learn$ time real 0m0.000s
user 0m0.000s
sys 0m0.000s
amosli@amosli-pc:~/learn$ date
2013年 12月 20日 星期五 :: CST
amosli@amosli-pc:~/learn$ exit
amosli@amosli-pc:~/learn$

进行多个用户之间进行广播视频会话:打开两个终端

(1)在终端1中输入以下命令:

mkfifo scriptfifo

(2)在终端2中输入以下命令:

cat scriptfifo

(3)返回终端1,输入以下命令:

script -f scriptfifo
commands...

这样就实现了广播,在线课堂类的作用,非常神奇!!

我自己实验的输出:

终端1:
amosli@amosli-pc:~$ mkfifo scriptfifo
amosli@amosli-pc:~$ script -f scriptfifo
Script started, file is scriptfifo
amosli@amosli-pc:~$ who
amosli tty7 -- :
amosli pts/ -- : (:0.0)
amosli pts/ -- : (:0.0)
amosli pts/ -- : (:0.0)
amosli pts/ -- : (:0.0)
amosli pts/ -- : (:0.0)
amosli@amosli-pc:~$ 终端2:
amosli@amosli-pc:~$ cat scriptfifo
Script started on 2013年12月20日 星期五 01时21分19秒
amosli@amosli-pc:~$ who
amosli tty7 -- :
amosli pts/ -- : (:0.0)
amosli pts/ -- : (:0.0)
amosli pts/ -- : (:0.0)
amosli pts/ -- : (:0.0)
amosli pts/ -- : (:0.0)
amosli@amosli-pc:~$

linux shell 脚本攻略学习4的更多相关文章

  1. linux shell 脚本攻略学习20--awk命令入门详解

    awk生于1977年,创始人有三个,分别为 Alfred Aho,Peter Weinberger, 和 Brian Kernighan,名称源于三个创始人的姓的首字母. 作用:处理文本文件. awk ...

  2. Linux Shell脚本攻略学习总结:一

    终端打印 终端打印的常用命令有两个:echo和print 首先,我先介绍echo 1.echo echo这个命令接受三种形式的参数,实例如下: echo "Hello World" ...

  3. linux shell 脚本攻略学习19--sed命令详解

    sed(意为流编辑器,英语“stream editor”的缩写)是Unix/linux常见的命令行程序.sed用来把文档或字符串里面的文字经过一系列编辑命令转换为另一种格式输出,即文本替换.sed通常 ...

  4. Linux Shell 脚本攻略学习--四

    linux中(chattr)创建不可修改文件的方法 在常见的linux扩展文件系统中(如ext2.ext3.ext4等),可以将文件设置为不可修改(immutable).某些文件属性可帮助我们将文件设 ...

  5. linux shell 脚本攻略学习3

    1.Bash中的READ命令 #读取n个字符存入变量 read -n number_of_chars variable_name 示例: amosli@amosli-pc:~$ read -n var ...

  6. linux shell 脚本攻略学习2

    1.关于文件描述符和重定向: 文件描述符是与一个打开的文件或数据流相关联的整数.文件描述符0.1以及2是系统预留的. 0——stdin(标准输入) 1——stdout(标准输出) 2——stderr( ...

  7. Linux Shell脚本攻略学习总结:三

    根据扩展名切分文件名 首先,我们先来看两个例子: file_jpg="sample.jgp" name=${file_jpg%.*} echo File name is : $na ...

  8. Linux Shell脚本攻略学习总结:二

    比较与测试 程序中的流程控制是由比较和测试语句来处理的. 我们可以用if,if else 以及逻辑运算符来执行测试,而用一些比较运算符来比较数据项.另外,有一个test 命令也可以用来进行测试.让我们 ...

  9. linux shell 脚本攻略学习12--文件权限详解,chmod命令详解,chown命令详解,chattr命令详解

    文件权限详解 一.chmod命令详解 文件权限和所有权是Unix/Linux文件系统最显著的特征之一.linux中的每一个文件都与多种权限类型相关联,在这些权限中主要分类为3种: 用户(User)是文 ...

  10. linux shell 脚本攻略学习18--grep命令详解

    grep(global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是unix/linux中用于文本搜索 ...

随机推荐

  1. LeetCode Anagrams My solution

    Anagrams Given an array of strings, return all groups of strings that are anagrams. Note: All inputs ...

  2. Centos7中firewalld防火锁墙的使用

    一.服务控制 启动: systemctl start firewalld 查看状态: systemctl status firewalld  停止: systemctl disable firewal ...

  3. Sqlite执行insert or ignore 或insert or replace语句。

    Sqlite执行insert or ignore 或insert or replace语句. ,); ,); 上面的第一条语句是每次执行时,如果不存在,则添加,如果存在,则更新. 上面的第二条语句是每 ...

  4. linux 新进程的创建

    慕课18原创作品转载请注明出处 + <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 一.背景知识: 1. ...

  5. 算法笔记_223:打印回型嵌套(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 *********** * * * ******* * * * * * * * *** * * * * * * * * * * *** * * * ...

  6. Percona-XtraBackup系列二:备份恢复

    #在备份较大数据量的时候推荐xtrabackup,这个工具比mysqldump要快很多. 一.Xtrabackup介绍 1,Xtrabackup是什么 Xtrabackup是一个对InnoDB做数据备 ...

  7. Mongostat 2.6详解

    Mongostat C:\Users\John>Mongostat connected to: 127.0.0.1 insert query update delete getmore comm ...

  8. Linux文件的软链接和硬链接

    1.Linux链接概念 Linux链接分两种,一种被称为硬链接(Hard Link).还有一种被称为符号链接(Symbolic Link).默认情况下.ln命令产生硬链接. 1.1索引节点 索引节点是 ...

  9. node.js 标准/错误输出 和 process.exit

    node.js中,各种模块有一种标准的写法: this._process.exec(command, options, function (err, stdout, stderr) { callbac ...

  10. logback的简单配置

    logback的简单配置: <?xml version="1.0" encoding="UTF-8"?> <configuration> ...