我有一个包含许多子目录的大文件夹,每个子目录都包含许多.txt
文件。我想将所有这些文件连接成一个.txt
文件。我可以使用 为每个子目录执行此操作cat *.txt>merged.txt
,但我正在尝试为大文件夹中的所有文件执行此操作。我该怎么做呢?
尝试
find /path/to/source -type f -name '*.txt' -exec cat {} + >mergedfile
Run Code Online (Sandbox Code Playgroud)
f
在/path/to/source
子目录中递归查找所有 '*.txt'文件并将所有文件连接成一个mergedfile
.
要连接其目录中的每个子目录文件,请执行以下操作:
find . -mindepth 1 -type d -execdir sh -c 'cat $1/*.txt >> $1/mergedfile' _ {} \;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10680 次 |
最近记录: |