Check if a drive has been Zeroed with xxd and uniq?
Clash Royale CLAN TAG#URR8PPP
I'm looking for a way to check if the entire binary contents of a USB device are purely 0s.
I'm trying this command:sudo xxd /dev/sdb | uniq
but it has no output and just runs forever.
I've considered the Sort command, but my understanding is that it requires a file to read rather than just the standard terminal output.
update: I realised I could check with sudo xxd -a /dev/sdb
, but my question still stands: is there a way to uniquely sort output of the terminal without saving it to a file first?
devices sort uniq hex
add a comment |
I'm looking for a way to check if the entire binary contents of a USB device are purely 0s.
I'm trying this command:sudo xxd /dev/sdb | uniq
but it has no output and just runs forever.
I've considered the Sort command, but my understanding is that it requires a file to read rather than just the standard terminal output.
update: I realised I could check with sudo xxd -a /dev/sdb
, but my question still stands: is there a way to uniquely sort output of the terminal without saving it to a file first?
devices sort uniq hex
1
cmp /dev/sdb /dev/zero
should becmp: EOF on /dev/sdb
. As for sort, it's justsomething | sort
, nothing special about it, except you'll run out of memory if you try dumping gigabytes of zeroes into it...
– frostschutz
Apr 18 '14 at 19:13
add a comment |
I'm looking for a way to check if the entire binary contents of a USB device are purely 0s.
I'm trying this command:sudo xxd /dev/sdb | uniq
but it has no output and just runs forever.
I've considered the Sort command, but my understanding is that it requires a file to read rather than just the standard terminal output.
update: I realised I could check with sudo xxd -a /dev/sdb
, but my question still stands: is there a way to uniquely sort output of the terminal without saving it to a file first?
devices sort uniq hex
I'm looking for a way to check if the entire binary contents of a USB device are purely 0s.
I'm trying this command:sudo xxd /dev/sdb | uniq
but it has no output and just runs forever.
I've considered the Sort command, but my understanding is that it requires a file to read rather than just the standard terminal output.
update: I realised I could check with sudo xxd -a /dev/sdb
, but my question still stands: is there a way to uniquely sort output of the terminal without saving it to a file first?
devices sort uniq hex
devices sort uniq hex
edited Apr 18 '14 at 12:12
Tom Bennett
asked Apr 18 '14 at 12:03
Tom BennettTom Bennett
112
112
1
cmp /dev/sdb /dev/zero
should becmp: EOF on /dev/sdb
. As for sort, it's justsomething | sort
, nothing special about it, except you'll run out of memory if you try dumping gigabytes of zeroes into it...
– frostschutz
Apr 18 '14 at 19:13
add a comment |
1
cmp /dev/sdb /dev/zero
should becmp: EOF on /dev/sdb
. As for sort, it's justsomething | sort
, nothing special about it, except you'll run out of memory if you try dumping gigabytes of zeroes into it...
– frostschutz
Apr 18 '14 at 19:13
1
1
cmp /dev/sdb /dev/zero
should be cmp: EOF on /dev/sdb
. As for sort, it's just something | sort
, nothing special about it, except you'll run out of memory if you try dumping gigabytes of zeroes into it...– frostschutz
Apr 18 '14 at 19:13
cmp /dev/sdb /dev/zero
should be cmp: EOF on /dev/sdb
. As for sort, it's just something | sort
, nothing special about it, except you'll run out of memory if you try dumping gigabytes of zeroes into it...– frostschutz
Apr 18 '14 at 19:13
add a comment |
3 Answers
3
active
oldest
votes
Simply using od
or hexdump
should be fine since these programs avoid outputting repeated lines (or use xxd -a
as above). Eg:
$ truncate -s 1M test
$ hexdump test
0000000 0000 0000 0000 0000 0000 0000 0000 0000
*
0100000
$ od test
0000000 000000 000000 000000 000000 000000 000000 000000 000000
*
4000000
If the drive is zeroed then the output won't be much different than this except that the final address will be much larger. If you see any other data, you could just hit Crtl-C.
To avoid continuing after non-zero data has been found and filling up the terminal, you could do something like this (in bash
):
count=0
stdbuf -oL od /dev/sdb |
while read line; do
echo "$line"
(( ++count > 3 )) && break
done
This will print at most 4 lines of output, from which you can tell if the drive is zeroed or not.
Top have done this dirtily with sort, you could have done sudo xxd /dev/sdb | sort -u
. Adding the -u
option to sort is equivalent to doing sort | uniq
.
add a comment |
xxd
doesn't strike me as the right hammer for this screw. You can run tr
to remove null bytes and see if there's anything left:
[ -n "$(</dev/sdb tr -dc '' | head -c 1)" ]
You can also use od
, which collapses null-filled lines:
[ "$(od -tx1 -An -w1 | head -n 2 | tr -d ' n')" = "00*" ]
add a comment |
i think this command will do the trick for you
xxd /dev/sdb | grep -v '0000 0000 0000 0000 0000 0000 0000 0000'
if the drive has been zeroed this command will return no output. Incase it has any bytes left on it, command will be happy to prompt it on the screen
Thanks
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f125380%2fcheck-if-a-drive-has-been-zeroed-with-xxd-and-uniq%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Simply using od
or hexdump
should be fine since these programs avoid outputting repeated lines (or use xxd -a
as above). Eg:
$ truncate -s 1M test
$ hexdump test
0000000 0000 0000 0000 0000 0000 0000 0000 0000
*
0100000
$ od test
0000000 000000 000000 000000 000000 000000 000000 000000 000000
*
4000000
If the drive is zeroed then the output won't be much different than this except that the final address will be much larger. If you see any other data, you could just hit Crtl-C.
To avoid continuing after non-zero data has been found and filling up the terminal, you could do something like this (in bash
):
count=0
stdbuf -oL od /dev/sdb |
while read line; do
echo "$line"
(( ++count > 3 )) && break
done
This will print at most 4 lines of output, from which you can tell if the drive is zeroed or not.
Top have done this dirtily with sort, you could have done sudo xxd /dev/sdb | sort -u
. Adding the -u
option to sort is equivalent to doing sort | uniq
.
add a comment |
Simply using od
or hexdump
should be fine since these programs avoid outputting repeated lines (or use xxd -a
as above). Eg:
$ truncate -s 1M test
$ hexdump test
0000000 0000 0000 0000 0000 0000 0000 0000 0000
*
0100000
$ od test
0000000 000000 000000 000000 000000 000000 000000 000000 000000
*
4000000
If the drive is zeroed then the output won't be much different than this except that the final address will be much larger. If you see any other data, you could just hit Crtl-C.
To avoid continuing after non-zero data has been found and filling up the terminal, you could do something like this (in bash
):
count=0
stdbuf -oL od /dev/sdb |
while read line; do
echo "$line"
(( ++count > 3 )) && break
done
This will print at most 4 lines of output, from which you can tell if the drive is zeroed or not.
Top have done this dirtily with sort, you could have done sudo xxd /dev/sdb | sort -u
. Adding the -u
option to sort is equivalent to doing sort | uniq
.
add a comment |
Simply using od
or hexdump
should be fine since these programs avoid outputting repeated lines (or use xxd -a
as above). Eg:
$ truncate -s 1M test
$ hexdump test
0000000 0000 0000 0000 0000 0000 0000 0000 0000
*
0100000
$ od test
0000000 000000 000000 000000 000000 000000 000000 000000 000000
*
4000000
If the drive is zeroed then the output won't be much different than this except that the final address will be much larger. If you see any other data, you could just hit Crtl-C.
To avoid continuing after non-zero data has been found and filling up the terminal, you could do something like this (in bash
):
count=0
stdbuf -oL od /dev/sdb |
while read line; do
echo "$line"
(( ++count > 3 )) && break
done
This will print at most 4 lines of output, from which you can tell if the drive is zeroed or not.
Top have done this dirtily with sort, you could have done sudo xxd /dev/sdb | sort -u
. Adding the -u
option to sort is equivalent to doing sort | uniq
.
Simply using od
or hexdump
should be fine since these programs avoid outputting repeated lines (or use xxd -a
as above). Eg:
$ truncate -s 1M test
$ hexdump test
0000000 0000 0000 0000 0000 0000 0000 0000 0000
*
0100000
$ od test
0000000 000000 000000 000000 000000 000000 000000 000000 000000
*
4000000
If the drive is zeroed then the output won't be much different than this except that the final address will be much larger. If you see any other data, you could just hit Crtl-C.
To avoid continuing after non-zero data has been found and filling up the terminal, you could do something like this (in bash
):
count=0
stdbuf -oL od /dev/sdb |
while read line; do
echo "$line"
(( ++count > 3 )) && break
done
This will print at most 4 lines of output, from which you can tell if the drive is zeroed or not.
Top have done this dirtily with sort, you could have done sudo xxd /dev/sdb | sort -u
. Adding the -u
option to sort is equivalent to doing sort | uniq
.
edited Apr 18 '14 at 12:33
answered Apr 18 '14 at 12:18
GraemeGraeme
25.1k46497
25.1k46497
add a comment |
add a comment |
xxd
doesn't strike me as the right hammer for this screw. You can run tr
to remove null bytes and see if there's anything left:
[ -n "$(</dev/sdb tr -dc '' | head -c 1)" ]
You can also use od
, which collapses null-filled lines:
[ "$(od -tx1 -An -w1 | head -n 2 | tr -d ' n')" = "00*" ]
add a comment |
xxd
doesn't strike me as the right hammer for this screw. You can run tr
to remove null bytes and see if there's anything left:
[ -n "$(</dev/sdb tr -dc '' | head -c 1)" ]
You can also use od
, which collapses null-filled lines:
[ "$(od -tx1 -An -w1 | head -n 2 | tr -d ' n')" = "00*" ]
add a comment |
xxd
doesn't strike me as the right hammer for this screw. You can run tr
to remove null bytes and see if there's anything left:
[ -n "$(</dev/sdb tr -dc '' | head -c 1)" ]
You can also use od
, which collapses null-filled lines:
[ "$(od -tx1 -An -w1 | head -n 2 | tr -d ' n')" = "00*" ]
xxd
doesn't strike me as the right hammer for this screw. You can run tr
to remove null bytes and see if there's anything left:
[ -n "$(</dev/sdb tr -dc '' | head -c 1)" ]
You can also use od
, which collapses null-filled lines:
[ "$(od -tx1 -An -w1 | head -n 2 | tr -d ' n')" = "00*" ]
answered Apr 19 '14 at 1:20
GillesGilles
534k12810781595
534k12810781595
add a comment |
add a comment |
i think this command will do the trick for you
xxd /dev/sdb | grep -v '0000 0000 0000 0000 0000 0000 0000 0000'
if the drive has been zeroed this command will return no output. Incase it has any bytes left on it, command will be happy to prompt it on the screen
Thanks
add a comment |
i think this command will do the trick for you
xxd /dev/sdb | grep -v '0000 0000 0000 0000 0000 0000 0000 0000'
if the drive has been zeroed this command will return no output. Incase it has any bytes left on it, command will be happy to prompt it on the screen
Thanks
add a comment |
i think this command will do the trick for you
xxd /dev/sdb | grep -v '0000 0000 0000 0000 0000 0000 0000 0000'
if the drive has been zeroed this command will return no output. Incase it has any bytes left on it, command will be happy to prompt it on the screen
Thanks
i think this command will do the trick for you
xxd /dev/sdb | grep -v '0000 0000 0000 0000 0000 0000 0000 0000'
if the drive has been zeroed this command will return no output. Incase it has any bytes left on it, command will be happy to prompt it on the screen
Thanks
answered Jan 14 at 16:49
MVnD3XMVnD3X
11
11
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f125380%2fcheck-if-a-drive-has-been-zeroed-with-xxd-and-uniq%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
cmp /dev/sdb /dev/zero
should becmp: EOF on /dev/sdb
. As for sort, it's justsomething | sort
, nothing special about it, except you'll run out of memory if you try dumping gigabytes of zeroes into it...– frostschutz
Apr 18 '14 at 19:13