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函数时 ...
随机推荐
- 利用adb 打开手机应用程序
通过adb打开android应用,我们需要做的第一步,就是查看当前app的入口,第二部,就是通过命令启动我们的app入口 查看app的启动画面 在运行下面命令时,先启动想要通过adb打开的app #查 ...
- TmsTimeUtils 时间戳
package com.sprucetec.tms.utils; import java.math.BigDecimal;import java.text.DateFormat;import java ...
- 【ElasticSearch】:索引Index、文档Document、字段Field
因为从ElasticSearch6.X开始,官方准备废弃Type了.对应数据库,对ElasticSearch的理解如下: ElasticSearch 索引Index 文档Document 字段Fiel ...
- git小乌龟工具TortoiseGit记住你的账号密码
在使用TortoiseGit的过程中,发下每次push或者pull都要重复输入账号密码,非常麻烦 怎么设置记住密码 在[系统盘]:\Users[你的用户名](比如C:\User\Administrat ...
- numpy中int类型与python中的int
[code] import numpy as np nparr = np.array([[1 ,2, 3, 4]]) np_int32 = nparr[0][0] # np_int=1 py_int ...
- 在Storm的Toplogy中设置多数据源Spout
上代码:主要看main方法中的设置. 如下代码是一般情况下的设置方法...Trident中设置多数据源看对应的博客总结 /** * 指定多个数据源 * 数字累加求和 * 先添加storm依赖 */ ...
- 理解web service 和 SOA
什么是SOA? SOA的全称为Service Oriented Architecture,即面向服务架构.这是一种架构理念.它的提出是在企业计算领域将耦合的系统划分为松耦合的无状态的服务.服务发布出来 ...
- Executor框架(一)
类继承关系 更详细的继承关系: ExecutorComplitionService类 在说Executor接口及实现类之前,先聊聊ExecutorComplitionService. 成员变量 pri ...
- RESTful SOA与DDD(领域驱动设计)
视频地址:http://www.infoq.com/presentations/RESTful-SOA-DDD 作者的一个DDD采访:http://www.informit.com/articles/ ...
- javascript实现代码高亮-wangHighLighter.js
1. 引言 (先贴出wangHighLighter.js的github地址:https://github.com/wangfupeng1988/wangHighLighter注意,程序和使用说明的更新 ...