Linux下的dd和cat

来源:互联网 发布:港澳游哪个软件好 编辑:程序博客网 时间:2024/04/27 23:17

linux下的两个很实用的命令, 一个切分, 一个合并.非常实用


1. dd

dd的参数:

Copy a file, converting and formatting according to the operands.  bs=BYTES        read and write up to BYTES bytes at a time  cbs=BYTES       convert BYTES bytes at a time  conv=CONVS      convert the file as per the comma separated symbol list  count=N         copy only N input blocks  ibs=BYTES       read up to BYTES bytes at a time (default: 512)  if=FILE         read from FILE instead of stdin  iflag=FLAGS     read as per the comma separated symbol list  obs=BYTES       write BYTES bytes at a time (default: 512)  of=FILE         write to FILE instead of stdout  oflag=FLAGS     write as per the comma separated symbol list  seek=N          skip N obs-sized blocks at start of output  skip=N          skip N ibs-sized blocks at start of input  status=WHICH    WHICH info to suppress outputting to stderr;                  'noxfer' suppresses transfer stats, 'none' suppresses all

if和of是输入输出

count是操作的块数

bs就是块的大小

seek是略过n个输出的块再写入

skip是略过输入的块数


2.  cat命令

很简单的常用法之一是把两个文件合并在一起

cat a b >c


3. 其它应用 

1.将本地的/dev/hdb整盘备份到/dev/hdd   dd if=/dev/hdb f=/dev/hdd              hdb –> 内存 -> hdd2.将/dev/hdb全盘数据备份到指定路径的image文件   dd if=/dev/hdb f=/root/image            hdb –> 内存 -> image文件3.将备份文件恢复到指定盘   dd if=/root/image f=/dev/hdb             image文件 –> 内存 -> hdb4.备份/dev/hdb全盘数据,并利用gzip工具进行压缩,保存到指定路径    dd if=/dev/hdb | gzip> /root/image.gz5.将压缩的备份文件恢复到指定盘   gzip -dc /root/image.gz | dd f=/dev/hdb6.备份磁盘开始的512个字节大小的MBR 主引导记录信息到指定文件   dd if=/dev/hda f=/root/image count=1 bs=512   默认从硬盘0柱面0磁道1扇区读取512个字节   count=1指仅拷贝一个块;bs=512指块大小为512个字节。   恢复:dd if=/root/image f=/dev/hda7.备份软盘   dd if=/dev/fd0 f=disk.img count=1  bs=1440k (即块大小为1.44M)8.拷贝内存内容到硬盘   dd if=/dev/mem f=/root/mem.bin  bs=1024 (指定块大小为1k)  9.拷贝光盘内容到指定文件夹,并保存为cd.iso镜像文件   dd if=/dev/cdrom(hdc)   of=/root/cd.iso10.增加swap交换分区文件大小第一步:创建一个大小为256M的文件:dd if=/dev/zero  of=/swapfile  bs=1024 count=262144第二步:把这个文件变成swap交换分区文件:mkswap /swapfile第三步:启用这个swap交换分区文件:swapon /swapfile第四步:编辑/etc/fstab文件,使在每次开机时自动加载swap交换分区文件:/swapfile    swap    swap    default   0 011.销毁磁盘数据     dd if=/dev/urandom f=/dev/hda1注意:利用随机的数据填充硬盘,在某些必要的场合可以用来销毁数据。12.测试硬盘的读写速度     dd if=/dev/zero bs=1024 count=1000000 f=/root/1Gb.file    写速度      dd if=/root/1Gb.file bs=64k | dd f=/dev/null      读速度通过以上两个命令输出的命令执行时间,可以计算出硬盘的读、写速度。13.确定硬盘的最佳块blocks大小:初始化硬盘     dd if=/dev/zero bs=1024 count=1000000 f=/root/1Gb.file    初始化硬盘     dd if=/dev/zero bs=2048 count=500000 f=/root/1Gb.file     初始化硬盘     dd if=/dev/zero bs=4096 count=250000 f=/root/1Gb.file     初始化硬盘     dd if=/dev/zero bs=8192 count=125000 f=/root/1Gb.file     初始化硬盘通过比较以上命令输出中所显示的命令执行时间,即可确定系统最佳的块大小。14.修复硬盘:                 自初始化硬盘     dd if=/dev/sda f=/dev/sda  SCSI硬盘 或dd if=/dev/hda f=/dev/hda   IDE



0 0