
cat(全称:concatenate)命令用于合并文件并将内容输出到标准设备,其核心功能是查看和合并文件内容。
所有用户均可使用
<code>cat [参数] [文件]</code>
常用参数说明:
-n:在每行前显示行号。-b:仅对非空行编号。-s:将多个连续空行压缩为一行。-E:在行尾显示 $ 标记。-T:用 ^I 表示 Tab 字符。-v:显示不可打印字符。主要用途:
cat file1 file2 > combined_file 将两个文件合并后保存为新文件。Ctrl+D 保存退出。ls -l | cat,表示将 ls -l 的结果传递给 cat 输出。查看文件内容: 显示 filename 文件的全部内容。
<code>cat filename</code>
创建文件: 覆盖写入文件 filename。
<code>cat > filename</code>
追加内容到已有文件: 在 filename 文件末尾添加内容。
<code>cat >> filename</code>
合并文件内容: 把 file1 和 file2 内容合并后写入 file3。
<code>cat file1 file2 > file3</code>
同时显示两个文件内容: 展示 file1 和 file2 的内容。
<code>cat file1 file2</code>
配合管道使用: 将 cat 输出作为其他命令的输入源。
<code>cat filename | command</code>
查看文件最后若干行: 显示 filename 的最后 10 行。
<code>cat filename | tail -n 10</code>
显示行号: 查看文件内容并添加行号。
<code>cat -n filename</code>
仅对非空行编号:
<code>cat -b filename</code>
压缩多余空行:
<code>cat -s filename</code>
显示制表符:
<code>cat -t filename</code>
显示行结束标记:
<code>cat -e filename</code>
带行号复制文件内容到另一个文件:
<code>cat -n textfile1 > textfile2</code>
多文件带行号合并追加到目标文件:
<code>cat -b textfile1 textfile2 >> textfile3</code>
清空指定文件内容:
<code>cat /dev/null > /etc/test.txt</code>
制作镜像文件: 如将软盘内容转存为镜像:
<code>cat /dev/fd0 > OUTFILE</code>
将镜像写入设备:
<code>cat IMG_FILE > /dev/fd0</code>
注意:
以上就是linux连接并显示文件内容是什么-cat 命令使用与实例的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号