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

Sha*_*ppa 10 linux dd hard-disk

我正在尝试从磁盘读取并希望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
Run Code Online (Sandbox Code Playgroud)

任何人都可以向我建议任何从磁盘读取的新方法吗?

Ser*_*rge 18

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

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

seek通常使用的(但不是总是)结合conv=notrunc以保持某些数据存在于输出流的开头。


Thu*_*shi 8

从手册页 dd

seek=BLOCKS
skip BLOCKS obs-sized blocks at start of output
skip=BLOCKS
skip BLOCKS ibs-sized blocks at start of input
Run Code Online (Sandbox Code Playgroud)

可以改写为,

seekoutput文件开头跳过 n 个块。

skipinput文件开头跳过 n 个块。


小智 7

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

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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

运行脚本的结果是:

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

Keep this, My Dear Friend, keep this.
Run Code Online (Sandbox Code Playgroud)

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

Keep thear Friend:IGNTHIS, keep this.
Run Code Online (Sandbox Code Playgroud)