用 cat 命令合并多个文本文件

把拆分的日志、CSV 分卷或章节文件合并成一个文件。

Linux文件文本低风险
运行 cat 文件1.txt 文件2.txt > 合并.txt,文件按你列出的顺序拼接。

01命令

命令
$ cat chapter1.txt chapter2.txt chapter3.txt > book.txt

02作用说明

cat 会按参数顺序把文件逐字节拼接,> 把结果重定向写入新文件,排在前面的文件内容在前。也可以用通配符:cat part*.txt > all.txt 会按文件名顺序合并所有匹配的文件。

03风险

风险低风险
!注意: 输出文件名不要和输入文件同名:cat a.txt b.txt > a.txt 会先把 a.txt 清空再读取,内容就丢了。另外如果源文件末尾没有换行符,前一个文件的最后一行会和下一个文件的第一行粘在一起。

04撤销

撤销
$ rm book.txt (the merged file; originals are untouched)

05来源

  • cat(1) — Linux manual page
    man7.org · community · 2026-09-17
    依据: cat concatenates the files named on the command line and writes them to standard output; redirection with > saves the result to a file.

最后验证: 2026-09-18 · 分类: 文件与文件夹

06相关方案