dd命令中的seek和skip有什么区别?

dd命令中的seek和skip有什么区别?

我正在尝试从磁盘读取数据,并希望dd命令随机发出每个请求,并检查磁盘的读取操作延迟,我使用了“查找”和“跳过”这两个操作是否有效?

dd if=/dev/rdsk/c2t5000CCA0284F36A4d0 skip=10  of=/dev/null bs=4k count=1024000
1024000+0 records in
1024000+0 records out
4194304000 bytes (4.2 GB) copied, 51.0287 s, 82.2 MB/s


dd if=/dev/rdsk/c2t5000CCA0284F36A4d0  seek=10  of=/dev/null bs=4k count=1024000
1024000+0 records in
1024000+0 records out
4194304000 bytes (4.2 GB) copied, 51.364 s, 81.7 MB/s

有人可以建议我使用从磁盘读取数据的新方法吗?

答案1

skipiseek(在某些实现中也称为dd)移动输入流的当前指针,同时seek移动输出流中的当前指针。

因此,通过使用skip您可以忽略输入流开头的一些数据。

通常seek(但并非总是)与 结合使用,conv=notrunc以保留输出流开头存在的一些数据。

答案2

从手册页dd

seek=BLOCKS
skip BLOCKS obs-sized blocks at start of output
skip=BLOCKS
skip BLOCKS ibs-sized blocks at start of input

这可以改写为,

seek从文件开头跳过 n 个块output

skip从文件开头跳过 n 个块input

答案3

以下示例首先准备一个输入文件和一个输出文件,然后将一部分输入复制到一部分输出文件中。

echo     "IGNORE:My Dear Friend:IGNORE"      > infile
echo "Keep this, OVERWRITE THIS, keep this." > outfile
cat infile
cat outfile
echo
dd status=none \
   bs=1 \
   if=infile \
   skip=7 \
   count=14 \
   of=outfile \
   conv=notrunc \
   seek=11

cat outfile

dd 的参数是:

status=none  Don't output final statistics as dd usually does - would disturb the demo
bs=1         All the following numbers are counts of bytes -- i.e., 1-byte blocks.
if=infile    The input file
skip=7       Ignore the first 7 bytes of input (skip "IGNORE:")
count=14     Transfer 14 bytes from input to output
of=outfile   What file to write into
conv=notrunc Don't delete old contents of the output file before writing.
seek=11      Don't overwrite the first 11 bytes of the output file
             i.e., leave them in place and start writing after them

运行脚本的结果是:

IGNORE:My Dear Friend:IGNORE
Keep this, OVERWRITE THIS, keep this.

Keep this, My Dear Friend, keep this.

如果交换“skip”和“seek”的值会发生什么? dd 会复制输入的错误部分并覆盖输出文件的错误部分:

Keep thear Friend:IGNTHIS, keep this.

相关内容