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函数时 ...
随机推荐
- 【有新题】OCP 12c 062出现大量新考题-14
choose two You plan to upgrade your Oracle Database 9i to Oracle Database 12c. Which two methods can ...
- .gitignore总结
git进行管理时,.gitignore是必不可少的,可以指定不需要提交到仓库的资源.最好在git init之后就创建 .gitignore文件,这是个好习惯,常用的配置及说明如下:
- (转)Java并发编程:线程池的使用方法
http://www.cnblogs.com/dolphin0520/p/3932921.html http://www.journaldev.com/1069/java-thread-pool-ex ...
- Composite组合模式(结构型模式)
1.概述 在面向对象系统中,经常会遇到一些具有"容器性质"的对象,它们自己在充当容器的同时,也充当其他对象的容器. 2.案例 需要构建一个容器系统,需要满足以下几点要求: (1). ...
- Linux环境下Java中文乱码解决方案
相信很多朋友遇到过Java的乱码问题,最近我也在解决一个“使用文本生成图片过程中中文以及特殊字符乱码”的问题:花了我大量时间,Debug了sun.font.sun.awt下面的各种源码,终于搞懂了其机 ...
- 选择 Python3.6 还是 Python 3.7
转自:白月黑羽在线教程:http://www.python3.vip/doc/blog/python/home/ 选择 Python3.6 还是 Python 3.7 Python 3.7 已经发布了 ...
- vue框架之自定义组件中使用v-model
通常 vue在html常见表单空间支持v-model双向绑定例如 <input v-model="message" placeholder="edit me&quo ...
- Chapter 3 Phenomenon——19
His unfriendliness intimidated me. 他的不友好恐吓到了我. My words came out with less severity than I'd intende ...
- Searching with Deep Learning 深度学习的搜索应用
本文首发于 vivo 互联网技术微信公众号 https://mp.weixin.qq.com/s/wLMvJPXXaND9xq-XMwY2Mg作者:Eike Dehling翻译:杨振涛 本文由来自 T ...
- linux之后台运行程序 nohup和& 的区别
1.nohup 用途:不挂断地运行命令,即使终端ssh关闭了也一直运行. 语法:nohup Command [ Arg … ] [ & ] 例:nohup start.sh & 无论是 ...