如何在 Linux 中获得等效的 /dev/one
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10905062/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I get an equivalent of /dev/one in Linux
提问by Ankur Agarwal
You can use
您可以使用
dd if=/dev/zero of=file count=1024 bs=1024
to zero fill a file.
零填充文件。
Instead of that I want to one fill a file. How do I do that?
相反,我想填充一个文件。我怎么做?
There is no /dev/one file, so how can I simulate that effect via on bash shell?
没有 /dev/one 文件,那么如何通过 bash shell 模拟这种效果?
采纳答案by Paused until further notice.
Try this:
尝试这个:
dd if=<(yes $'' | tr -d "\n") of=file count=1024 bs=1024
Substitute $'\377'
or $'\xFF'
if you want all the bits to be ones.
替换$'\377'
或者$'\xFF'
如果您希望所有位都为 1。
回答by larsks
Well, you could do this:
好吧,你可以这样做:
dd if=/dev/zero count=1024 bs=1024 |
tr 'tr 'pv /dev/zero |tr \000 \377 >targetfile
' '7' < /dev/zero | dd bs=64K of=/dev/sdx
0' 'cat /dev/zero |tr \000 \377 |hexdump -C
1' > file
回答by monkeybus
This should be much faster. Choose your blocksizes (or add counts) like you need at. Writing ones to a SSD-Disk till full with a blocksize of 99M gave me 350M/s write performance.
这应该快得多。根据需要选择块大小(或添加计数)。以 99M 的块大小将它们写入 SSD 磁盘直到满给了我 350M/s 的写入性能。
回答by nobar
...where \377
is the octal representation of 255
(a byte with all bits set to one). Why tr
only works with octal numbers, I don't know -- but be careful not to subconsciously translate this to 3FF.
...其中\377
是255
(所有位都设置为 1 的字节)的八进制表示。为什么tr
只适用于八进制数,我不知道——但注意不要下意识地将其转换为3FF。
The syntax for using tr
is error prone. I recommend verifying that it is making the desired translation...
使用的语法tr
很容易出错。我建议验证它正在制作所需的翻译......
Note: pv
is a nice utility that replaces cat
and adds a progress/rate display.
注意:pv
是一个很好的实用程序,可以替换cat
并添加进度/速率显示。