shell cat 合并多个文件
在Shell中,你可以使用cat命令来合并多个文件。以下是一个基本的示例,它将两个文件file1.txt和file2.txt合并为一个新文件merged.txt:
shell
cat file1.txt file2.txt > merged.txt
如果你想要追加文件内容而不是覆盖,可以使用>>操作符:
shell
cat file1.txt >> merged.txt
cat file2.txt >> merged.txt
如果要合并当前目录下所有.txt文件,可以使用通配符*:
shell
cat *.txt > merged.txt
如果文件很多,你可以使用find命令结合cat来合并特定目录下的所有文件:
shell
find /path/to/directory -type f -name "*.txt" -exec cat {} + > merged.txt
这个命令会查找指定目录下所有扩展名为.txt的文件,并将它们合并到merged.txt中。