linux命令详解:cat命令
转:http://www.cnblogs.com/lwgdream/archive/2013/11/06/3409802.html
前言
cat命令用于读取文本文件,并且能够显示行号、特殊字符等。
使用说明
-n 对每行进行编号,包括空行
-b 对每行进行编号,不包括空行
-s 压缩连续的空行
-A 显示特殊字符,换行符、制表符等
使用举例
cat 读取文本文件
1: [root@master lianxi]# cat f2: # Generated automatically from man.conf.in by the3: # configure script.
cat 从标准输入读取
通过管道读取其命令的输出,cmd | cat -
1: [root@master lianxi]# echo "hello world" | cat2: hello world3: [root@master lianxi]# echo "hello world" | cat -4: hello world
-A 显示特殊字符
换行符$、制表符^I
1: [root@master lianxi]# cat f2: # Generated automatically from man.conf.in by the3: # configure script. config4: [root@master lianxi]# cat -A f5: # Generated automatically from man.conf.in by the$6: # configure script.^Iconfig$
添加行号
-n 每行都添加行号,包括空行
1: [root@master lianxi]# cat -n f2: 1 # Generated automatically from man.conf.in by the3: 24: 3 # configure script. config-b 除了空行,其他每行都加上行号
1: [root@master lianxi]# cat -b f2: 1 # Generated automatically from man.conf.in by the3:4: 2 # configure script. config-s 压缩连续空行
如下,该文件有3个连续的空行,被压缩成了一个
1: [root@master lianxi]# cat -n f2: 1 # Generated automatically from man.conf.in by the3: 24: 35: 46: 5 # configure script. config7: [root@master lianxi]# cat -s -n f8: 1 # Generated automatically from man.conf.in by the9: 210: 3 # configure script. config合并文件
cat f1 f2
1: [root@master lianxi]# cat f2: # Generated automatically from man.conf.in by the3:4:5:6: # configure script. config7: [root@master lianxi]# cat f18: # Generated automatically from man.conf.in by the9: # configure script. config10: [root@master lianxi]# cat f f111: # Generated automatically from man.conf.in by the12:13:14:15: # configure script. config16: # Generated automatically from man.conf.in by the17: # configure script. configcat f1 – f2 - 表示从标准输入读取
cat 是一次读取多个文件,先读取f1,再从 – (标准输入读取),在读取f2
1: [root@master lianxi]# cat f2: lwg3: [root@master lianxi]# cat f14: yangzhen5: [root@master lianxi]# echo "love" | cat f - f16: lwg7: love8: yangzhen
特殊说明
1)cat读取的是文本文件,读取文件文件肯定会因为无法“正确”解码而出现乱码
2)cat 读取文本文件的时候,是按照系统默认的编码方式来进行解码的。如果文本文件本身编码和默认编码不一致,可能也会出现乱码。可以先通过iconv命令来进行转码
3)cat命令读取多个是顺序依次读取的
总结
用cat命令来读取文本文件,也是linux中最常用的命令之一。
linux命令详解:cat命令的更多相关文章
- linux shell 脚本攻略学习14--head命令详解,tail命令详解
当要查看上千行的大文件时,我们可不会用cat命令把整个文件内容给打印出来,相反,我们可能只需要看文件的一小部分地内容(例如文件的前十行和后十行),我们也有可能需要打印出来前n行或后n行,也有可能打印除 ...
- linux shell 脚本攻略学习13--file命令详解,diff命令详解
一.file命令详解 find命令可以通过查看文件内容来找出特定类型的文件,在UNIX/ Linux系统中,文件类型并不是由文件扩展名来决定的(windows中却正是这么做的),file命令的目的是从 ...
- linux shell 脚本攻略学习 -- head命令详解, tail命令详解
当要查看上千行的大文件时,我们可不会用cat命令把整个文件内容给打印出来,相反,我们可能只需要看文件的一小部分地内容(例如文件的前十行和后十行),我们也有可能需要打印出来前n行或后n行,也有可能打印除 ...
- [转]dd命令、cp命令详解+dd命令、cp命令对比 ---delong
出处:http://blog.csdn.net/sun_app/article/details/18263299 1.dd命令详解 1)中文man手册dd的解释 NAME dd - 转换和 ...
- linux命令大全之watch命令详解(监测命令运行结果)
watch是一个非常实用的命令,基本所有的Linux发行版都带有这个小工具,如同名字一样,watch可以帮你监测一个命令的运行结果,省得你一遍遍的手动运行.在Linux下,watch是周期性的执行下个 ...
- linux命令详解:df命令
转:http://www.cnblogs.com/lwgdream/p/3413579.html 前言 df命令用来查看系统的space和inode使用情况,也是常用命令之一 使用说明 -a 显示所有 ...
- linux系统find命令详解+xargs命令 、exec命令
find 作用:查找文件 1.name: 指定文件名 例子1. 找到以du结尾的文件 ╭─root@localhost.localdomain ~ ╰─➤ find / -name "*du ...
- tar 命令详解 / xz 命令
]# tar [-cxtzjvfpPN] 文件与目录 ....参数:-c :建立一个压缩文件的参数指令(create 的意思):-x :解开一个压缩文件的参数指令!-t :查看 tarfile 里面的 ...
- top显示命令详解+top命令使用
http://blog.csdn.net/u014226549/article/details/22041289
- Linux CAT与ECHO命令详解 <<EOF EOF
Linux CAT与ECHO命令详解 cat命令是Linux下的一个文本输出命令,通常是用于观看某个文件的内容的: cat主要有三大功能: .一次显示整个文件. $ cat filename .从键盘 ...
随机推荐
- 原始套接字--简易ping程序
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> ...
- Java Web Action DAO Service层次理解
参考来源:http://blog.csdn.net/inter_peng/article/details/41021727 1. Action/Service/DAO简介: Action是管理业务(S ...
- hdu1576逆元的一道水题
hdu 1576 Problem Description 要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1). ...
- 第十七篇:django基础(二)
本篇内容 简单图书crm系统 编写views views:作为MVC中的C,接收用户的输入,调用数据库Model层和业务逻辑Model层,处理后将处理结果渲染到V层中去. app01/views.py ...
- [洛谷P1972][SDOI2009]HH的项链
题目大意:给你一串数字,多次询问区间内数字的种类数 题解:莫队 卡点:洛谷数据加强,开了个$O(2)$ C++ Code: #include <cstdio> #include <a ...
- java 复习整理(五 类加载机制与对象初始化)
类加载机制与对象初始化 一 . 类加载机制 类加载机制是指.class文件加载到jvm并形成Class对象的机制.之后应用可对Class对象进行实例化并调用.类加载机制可在运行时动态加载外部的类, ...
- 文件排版(codevs 1300)
题目描述 Description 写电子邮件是有趣的,但不幸的是经常写不好看,主要是因为所有的行不一样长,你的上司想要发排版精美的电子邮件,你的任务是为他编写一个电子邮件排版程序. 完成这个任务最简单 ...
- 生成 RSA 私钥及公钥
$ openssl # 进入 OpenSSL 程序 OpenSSL> genrsa -out rsa_private_key.pem 1024 # 生成私钥 OpenSSL> pkcs8 ...
- Windows.Forms Panel 动态加载用户控件 UserControl
创建好一个Windows Forms程序,在创建好的程序中Form1添加一个Panel控件 如图:
- 自定义View Measure过程(2)
目录 目录 1. 作用 测量View的宽/高 在某些情况下,需要多次测量(measure)才能确定View最终的宽/高: 在这种情况下measure过程后得到的宽/高可能是不准确的: 建议在layou ...