Linux常用基本命令(cat)
cat命令
作用:连接多个文件并且打印到屏幕输出,或者重定向到其他文件,也可以用来查看显示单个文件,或者多个文件。
格式:
cat [option] [file]
1,最简单的用法,直接跟文件名称,查看文件内容
ghostwu@dev:~/linux/cat$ ls
ghostwu@dev:~/linux/cat$ echo 'hello,my name is ghostwu, how are you?' > test.txt
ghostwu@dev:~/linux/cat$ cat test.txt
hello,my name is ghostwu, how are you?
ghostwu@dev:~/linux/cat$
2,也可以使用如下方式,向文件写入或者追加内容
ghostwu@dev:~/linux/cat$ ls
test.txt
ghostwu@dev:~/linux/cat$ cat >> test.txt << EOF
> 这是我新增的内容
> 这是第三行内容
> EOF
ghostwu@dev:~/linux/cat$ cat test.txt
hello,my name is ghostwu, how are you?
这是我新增的内容
这是第三行内容
3,-n与-b 都是对文件进行编号,-b不会对空行编号
ghostwu@dev:~/linux/cat$ cat test.txt
hello,my name is ghostwu, how are you?
这是我新增的内容
这是第三行内容
ghostwu@dev:~/linux/cat$ cat >> test.txt << EOF
>
>
> 上面加入了两个空行
> EOF
ghostwu@dev:~/linux/cat$ cat test.txt
hello,my name is ghostwu, how are you?
这是我新增的内容
这是第三行内容 上面加入了两个空行
ghostwu@dev:~/linux/cat$ cat -n test.txt
hello,my name is ghostwu, how are you?
这是我新增的内容
这是第三行内容 上面加入了两个空行
ghostwu@dev:~/linux/cat$ cat -b test.txt
hello,my name is ghostwu, how are you?
这是我新增的内容
这是第三行内容 上面加入了两个空行
ghostwu@dev:~/linux/cat$
4,-E 在每一行的行尾显示美元符号
ghostwu@dev:~/linux/cat$ cat -E test.txt
hello,my name is ghostwu, how are you?$
这是我新增的内容$
这是第三行内容$
$
$
上面加入了两个空行$
5,-s: 把两个以上连续的空行,变成一个
ghostwu@dev:~/linux/cat$ cat -n test.txt
hello,my name is ghostwu, how are you?
这是我新增的内容
这是第三行内容 上面加入了两个空行 上面加入了一个空行
ghostwu@dev:~/linux/cat$ cat -ns test.txt
hello,my name is ghostwu, how are you?
这是我新增的内容
这是第三行内容 上面加入了两个空行 上面加入了一个空行
6,利用/dev/null 删除文件内容
ghostwu@dev:~/linux/cat$ cat test.txt
hello,my name is ghostwu, how are you?
这是我新增的内容
这是第三行内容 上面加入了两个空行 上面加入了一个空行
ghostwu@dev:~/linux/cat$ cat /dev/null > test.txt
ghostwu@dev:~/linux/cat$ cat test.txt
7,利用重定向写入内容
ghostwu@dev:~/linux/cat$ cat test.txt
ghostwu@dev:~/linux/cat$ cat > test.txt
this is ghostwu
how are you
ghostwu@dev:~/linux/cat$ cat test.txt
this is ghostwu
how are you
内容输入完毕,用ctrl+d或者ctrl+c中断输入
8,显示多个文件内容
ghostwu@dev:~/linux/cat$ cat > abc.txt
this is abc.txt
ghostwu@dev:~/linux/cat$ cat test.txt abc.txt
this is ghostwu
how are you
this is abc.txt
Linux常用基本命令(cat)的更多相关文章
- Linux常用基本命令(less)
转: Linux常用基本命令(less) LESS:跟more命令的功能类似,都是用于分页显示内容,但是他的性能比more更高,功能比more更丰富,他读取文件是按需加载 格式: less [opti ...
- Linux 常用基本命令及应用技巧
需要pdf 版 联系我 我的文件中有目录一.Linux 的常用基本命令................................................................. ...
- Linux常用命令 - cat命令详解
21篇测试必备的Linux常用命令,每天敲一篇,每次敲三遍,每月一循环,全都可记住!! https://www.cnblogs.com/poloyy/category/1672457.html 获取t ...
- 【Linux】linux常用基本命令(转)
(转自:http://blog.csdn.net/xiaoguaihai/article/details/8705992) Linux中许多常用命令是必须掌握的,这里将我学linux入门时学的一些常用 ...
- 【Linux】linux常用基本命令
Linux中许多常用命令是必须掌握的,这里将我学linux入门时学的一些常用的基本命令分享给大家一下,希望可以帮助你们. 这个是我将鸟哥书上的进行了一下整理的,希望不要涉及到版权问题. 1.显示日 ...
- linux常用基本命令
Linux中许多常用命令是必须掌握的,这里将我学linux入门时学的一些常用的基本命令分享给大家一下,希望可以帮助你们. 系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器 ...
- linux常用基本命令整理小结
linux系统遵循的基本原则 由目标单一的小程序组成,组合小程序完成复杂任务: 一切皆文件: 尽量避免捕捉用户接口: 配置文件保存为纯文本文件: Linux命令行常识 命令格式 命令+选项+参数 选项 ...
- Linux 常用基本命令
这两天有俩哥们问了我linux的事,问我在工作中需不需要用到,需不需要学会 一个是工作1年不到的,我跟他说,建议你学学,在以后肯定是要用到的,虽然用到的机会不多,但是会总比不会好 另一个是工作6年的, ...
- Linux常用基本命令:三剑客命令之-awk内置函数用法
awk的内置函数大致可以分类为算数函数.字符串函数.时间函数.其他函数等 算数函数 最常用的算数函数有rand函数.srand函数.int函数. 可以使用rand函数生成随机数,但是使用rand函数时 ...
随机推荐
- Python 库,资源
库名称简介 Chardet字符编码探测器,可以自动检测文本.网页.xml的编码. colorama主要用来给文本添加各种颜色,并且非常简单易用. Prettytable主要用于在终端或浏览器端构建格式 ...
- python之ETL数据清洗案例源代码
#python语言 import pandas as pd import time data = pd.read_excel('ETL_数据清洗挑战.xlsx','测试数据',dtype=str)#读 ...
- 6_文件IO
1. 基本文件读取 readline(),readlines(),write(),writelines() f.read(size),指定读取文件的字节数,需要注意的是 ...
- POJ 2610
#include<iostream> #include<iomanip> using namespace std; int main() { //freopen("a ...
- odoo API装饰器one、model、multi的区别
1.one装饰器详解 odoo新API中定义方式: date=fields.Date(string="date",compute="_get_date") ...
- date命令使用文档.txt
date命令的帮助信息 [root@localhost source]# date --help用法:date [选项]... [+格式] 或:date [-u|--utc|--universal] ...
- Spring4 mvc+maven 框架搭建(1)
这篇博客其实很早就应该写,早在半年前,因为对SpringMVC感兴趣,便自学了一下Spring.一段时间的学习后,对Spring有了一个基本的了解,于是想着自己动手搭建一个SpringMvc的框架出来 ...
- Android开发艺术探索学习笔记(四)
第四章 View的工作原理 4.1初识ViewRoot和DecorView ViewRoot是连接WindowManager和DecorView的纽带,View的三大流程均是通过ViewRoot来完成 ...
- FineBI学习系列之FineBI的Windows里安装步骤(图文详解)
不多说,直接上干货! 先进入FineBI官网. http://www.finebi.com/product/download/ windows系统里FineBI的安装流程 1.从FineBI官网下载 ...
- sql server 2008 R2
SQL SERVER 2008 R2序列号: 数据中心版:PTTFM-X467G-P7RH2-3Q6CG-4DMYB 开 发者 版:MC46H-JQR3C-2JRHY-XYRKY-QWPVM 企 ...