
我想使用 shell 命令有效地合併二進位文件,我很快就找到了像這樣的經典方法:
cat file1 file2 > file3
不錯,但是:
- 很慢。 IO存取速度慢。
- 它需要額外的空間。我不想複製文件。只需將它們連接起來即可。
檔案系統非常適合處理檔案碎片。我們不能使用這種機制來合併文件嗎?
答案1
答案2
list.txt
將檔案名稱依序放入名為「以換行符號分隔」的文字檔案中。然後在 bash 中運行:
while read line; do echo -n . ; dd if="$line" of=out status=none conv=notrunc oflag=append; done < list.txt
這將在當前目錄中建立串聯檔案“out”。
答案3
dd if=firstfile.raw > completedfile.raw
dd if=nfile.raw >> completedfile.raw
dd if=lastfile.raw >> completedfile.raw