24. 如何使用 ‘cat’ 命令備份或複製 Linux 分區

A rough utilization of Linux cat command would be to make a full disk backup or a disk partition backup or cloning of a disk partition by redirecting the command output against the partition of a hard disk, or USB stick or a local image file or write the output to a network socket.

Linux Filesystem Backup Using ‘cat’ Command

你想知道为什么我们应该在后者轻松完成相同工作的情况下使用cat,这是很正常的想法,然而,我最近意识到在速度和性能方面,dd比cat快得多。

I do agree that dd provides, even more, options and also very useful in dealing with large backups such as tape drives (How to Clone Linux Partitions Using ‘dd’ Command), whereas cat includes lesser option and it’s not necessarily a worthy dd replacement but still, remains an option wherever applicable.

建议阅读: 如何使用Clonezilla克隆或备份Linux磁盘

相信我,它可以成功地将分区内容复制到一个新的未格式化的分区中。唯一的要求是提供一个有效的硬盘分区,其最小大小为现有数据,并且没有任何文件系统。

在下面的示例中,将第一个硬盘上的第一个分区,对应于/boot分区,即/dev/sda1,克隆到第二个硬盘的第一个分区(即/dev/sdb1),使用了Linux的重定向运算符。

# cat /dev/sda1 > /dev/sdb1
Full Disk Partition Backup in Linux

命令完成后,克隆的分区被挂载到/mnt上,并列出两个挂载点目录以检查是否缺少任何文件。

# mount /dev/sdb1 /mnt
# ls /mnt
# ls /boot
Verify Cloned Partition Files

为了将分区文件系统扩展到最大的大小,请使用以下命令并具有root权限。

建議閱讀: 14款出色的Linux系統備份工具

$ sudo resize2fs /dev/sdb1
Resize or Extend Partition Size in Linux

`cat` 命令是 Linux 中 manipulation 文字文件和一些特殊的多媒體文件的优秀工具,但應避免用於二進制數據文件或串接 shebang 文件。對於其他所有選項,不要猶豫,從控制台執行 `man cat`。

$ man cat

令人驚訝的是,有一個名為 `tac` 的另一個命令,是的,我正在談論 `tac`,這是 `cat` 命令的反倒版(也寫得反倒)),倒序顯示文件的每行,想了解更多關於 `tac` 的信息,閱讀 Linux 中如何使用 Tac 命令。

Source:
https://www.tecmint.com/backup-or-clone-linux-partitions-using-cat-command/