Wipe a USB flash drive and recreate a filesystem
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I'm using this to wipe a USB flash drive and recreate a FAT filesystem:
dd if=/dev/zero of=/dev/sdb bs=1M #I don't need more advanced wiping
fdisk /dev/sdb
(a few keystrokes to select partition type, etc.)
mkfs.fat /dev/sdb1
The fact that I have to manually do a few keystrokes is annoying. How could I do all of this in one step, without any intervention? Something like:
dd if=/dev/zero of=/dev/sdb bs=1M && ??? &&& mkfs.fat /dev/sdb1
hard-disk dd fdisk mkfs disk-cleanup
add a comment |Â
up vote
0
down vote
favorite
I'm using this to wipe a USB flash drive and recreate a FAT filesystem:
dd if=/dev/zero of=/dev/sdb bs=1M #I don't need more advanced wiping
fdisk /dev/sdb
(a few keystrokes to select partition type, etc.)
mkfs.fat /dev/sdb1
The fact that I have to manually do a few keystrokes is annoying. How could I do all of this in one step, without any intervention? Something like:
dd if=/dev/zero of=/dev/sdb bs=1M && ??? &&& mkfs.fat /dev/sdb1
hard-disk dd fdisk mkfs disk-cleanup
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm using this to wipe a USB flash drive and recreate a FAT filesystem:
dd if=/dev/zero of=/dev/sdb bs=1M #I don't need more advanced wiping
fdisk /dev/sdb
(a few keystrokes to select partition type, etc.)
mkfs.fat /dev/sdb1
The fact that I have to manually do a few keystrokes is annoying. How could I do all of this in one step, without any intervention? Something like:
dd if=/dev/zero of=/dev/sdb bs=1M && ??? &&& mkfs.fat /dev/sdb1
hard-disk dd fdisk mkfs disk-cleanup
I'm using this to wipe a USB flash drive and recreate a FAT filesystem:
dd if=/dev/zero of=/dev/sdb bs=1M #I don't need more advanced wiping
fdisk /dev/sdb
(a few keystrokes to select partition type, etc.)
mkfs.fat /dev/sdb1
The fact that I have to manually do a few keystrokes is annoying. How could I do all of this in one step, without any intervention? Something like:
dd if=/dev/zero of=/dev/sdb bs=1M && ??? &&& mkfs.fat /dev/sdb1
hard-disk dd fdisk mkfs disk-cleanup
asked Oct 16 '17 at 8:27
Basj
6181731
6181731
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
Here-document syntax allows you to use fdisk
non-interactively:
fdisk /dev/sdb <<EOF
n
p
t
b
p
q
EOF
Because this is just an example, I used p
and q
so no changes are written. Use w
after your verified sequence.
Note a blank line corresponds to sole Enter. The point is you can pass your keystrokes this way.
Alternatively you can write those lines (between two EOF
-s) to a file, say fdisk.commands
, and then:
fdisk /dev/sdb < fdisk.commands
Or without a file (from a comment, thank you Rastapopoulos):
fdisk /dev/sdb <<< $'nnpnnnntnbnpnq'
Another way:
printf '%sn' "n" "p" "" "" "" "t" "b" "p" "q" | fdisk /dev/sdb
There's also sfdisk
. You may find its syntax more suitable for you.
OK, this was a mistake.
â Kamil Maciorowski
Oct 16 '17 at 9:16
Check my updated answer. You shouldn't expect you can do all of this in strictly one command. Unix philosophy says one tool should do one thing. You're doing three things.
â Kamil Maciorowski
Oct 16 '17 at 9:25
1
You can use<<<
:fdisk /dev/sdb <<< $'nnpnnnntnbnpn'
, no?
â Rastapopoulos
Oct 16 '17 at 10:22
1
@Rastapopoulos You're right. Thanks for your input.
â Kamil Maciorowski
Oct 16 '17 at 10:31
add a comment |Â
up vote
0
down vote
Based on @KamilMaciorowski's answer (full credit to him), here is what I finally use:
sudo dd if=/dev/zero of=/dev/sdb bs=1M && sudo fdisk /dev/sdb <<< $'nnpnnnntnbnpnwn' && sudo mkfs.fat /dev/sdb1
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Here-document syntax allows you to use fdisk
non-interactively:
fdisk /dev/sdb <<EOF
n
p
t
b
p
q
EOF
Because this is just an example, I used p
and q
so no changes are written. Use w
after your verified sequence.
Note a blank line corresponds to sole Enter. The point is you can pass your keystrokes this way.
Alternatively you can write those lines (between two EOF
-s) to a file, say fdisk.commands
, and then:
fdisk /dev/sdb < fdisk.commands
Or without a file (from a comment, thank you Rastapopoulos):
fdisk /dev/sdb <<< $'nnpnnnntnbnpnq'
Another way:
printf '%sn' "n" "p" "" "" "" "t" "b" "p" "q" | fdisk /dev/sdb
There's also sfdisk
. You may find its syntax more suitable for you.
OK, this was a mistake.
â Kamil Maciorowski
Oct 16 '17 at 9:16
Check my updated answer. You shouldn't expect you can do all of this in strictly one command. Unix philosophy says one tool should do one thing. You're doing three things.
â Kamil Maciorowski
Oct 16 '17 at 9:25
1
You can use<<<
:fdisk /dev/sdb <<< $'nnpnnnntnbnpn'
, no?
â Rastapopoulos
Oct 16 '17 at 10:22
1
@Rastapopoulos You're right. Thanks for your input.
â Kamil Maciorowski
Oct 16 '17 at 10:31
add a comment |Â
up vote
2
down vote
accepted
Here-document syntax allows you to use fdisk
non-interactively:
fdisk /dev/sdb <<EOF
n
p
t
b
p
q
EOF
Because this is just an example, I used p
and q
so no changes are written. Use w
after your verified sequence.
Note a blank line corresponds to sole Enter. The point is you can pass your keystrokes this way.
Alternatively you can write those lines (between two EOF
-s) to a file, say fdisk.commands
, and then:
fdisk /dev/sdb < fdisk.commands
Or without a file (from a comment, thank you Rastapopoulos):
fdisk /dev/sdb <<< $'nnpnnnntnbnpnq'
Another way:
printf '%sn' "n" "p" "" "" "" "t" "b" "p" "q" | fdisk /dev/sdb
There's also sfdisk
. You may find its syntax more suitable for you.
OK, this was a mistake.
â Kamil Maciorowski
Oct 16 '17 at 9:16
Check my updated answer. You shouldn't expect you can do all of this in strictly one command. Unix philosophy says one tool should do one thing. You're doing three things.
â Kamil Maciorowski
Oct 16 '17 at 9:25
1
You can use<<<
:fdisk /dev/sdb <<< $'nnpnnnntnbnpn'
, no?
â Rastapopoulos
Oct 16 '17 at 10:22
1
@Rastapopoulos You're right. Thanks for your input.
â Kamil Maciorowski
Oct 16 '17 at 10:31
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Here-document syntax allows you to use fdisk
non-interactively:
fdisk /dev/sdb <<EOF
n
p
t
b
p
q
EOF
Because this is just an example, I used p
and q
so no changes are written. Use w
after your verified sequence.
Note a blank line corresponds to sole Enter. The point is you can pass your keystrokes this way.
Alternatively you can write those lines (between two EOF
-s) to a file, say fdisk.commands
, and then:
fdisk /dev/sdb < fdisk.commands
Or without a file (from a comment, thank you Rastapopoulos):
fdisk /dev/sdb <<< $'nnpnnnntnbnpnq'
Another way:
printf '%sn' "n" "p" "" "" "" "t" "b" "p" "q" | fdisk /dev/sdb
There's also sfdisk
. You may find its syntax more suitable for you.
Here-document syntax allows you to use fdisk
non-interactively:
fdisk /dev/sdb <<EOF
n
p
t
b
p
q
EOF
Because this is just an example, I used p
and q
so no changes are written. Use w
after your verified sequence.
Note a blank line corresponds to sole Enter. The point is you can pass your keystrokes this way.
Alternatively you can write those lines (between two EOF
-s) to a file, say fdisk.commands
, and then:
fdisk /dev/sdb < fdisk.commands
Or without a file (from a comment, thank you Rastapopoulos):
fdisk /dev/sdb <<< $'nnpnnnntnbnpnq'
Another way:
printf '%sn' "n" "p" "" "" "" "t" "b" "p" "q" | fdisk /dev/sdb
There's also sfdisk
. You may find its syntax more suitable for you.
edited Oct 16 '17 at 10:31
answered Oct 16 '17 at 8:59
Kamil Maciorowski
1,0791523
1,0791523
OK, this was a mistake.
â Kamil Maciorowski
Oct 16 '17 at 9:16
Check my updated answer. You shouldn't expect you can do all of this in strictly one command. Unix philosophy says one tool should do one thing. You're doing three things.
â Kamil Maciorowski
Oct 16 '17 at 9:25
1
You can use<<<
:fdisk /dev/sdb <<< $'nnpnnnntnbnpn'
, no?
â Rastapopoulos
Oct 16 '17 at 10:22
1
@Rastapopoulos You're right. Thanks for your input.
â Kamil Maciorowski
Oct 16 '17 at 10:31
add a comment |Â
OK, this was a mistake.
â Kamil Maciorowski
Oct 16 '17 at 9:16
Check my updated answer. You shouldn't expect you can do all of this in strictly one command. Unix philosophy says one tool should do one thing. You're doing three things.
â Kamil Maciorowski
Oct 16 '17 at 9:25
1
You can use<<<
:fdisk /dev/sdb <<< $'nnpnnnntnbnpn'
, no?
â Rastapopoulos
Oct 16 '17 at 10:22
1
@Rastapopoulos You're right. Thanks for your input.
â Kamil Maciorowski
Oct 16 '17 at 10:31
OK, this was a mistake.
â Kamil Maciorowski
Oct 16 '17 at 9:16
OK, this was a mistake.
â Kamil Maciorowski
Oct 16 '17 at 9:16
Check my updated answer. You shouldn't expect you can do all of this in strictly one command. Unix philosophy says one tool should do one thing. You're doing three things.
â Kamil Maciorowski
Oct 16 '17 at 9:25
Check my updated answer. You shouldn't expect you can do all of this in strictly one command. Unix philosophy says one tool should do one thing. You're doing three things.
â Kamil Maciorowski
Oct 16 '17 at 9:25
1
1
You can use
<<<
: fdisk /dev/sdb <<< $'nnpnnnntnbnpn'
, no?â Rastapopoulos
Oct 16 '17 at 10:22
You can use
<<<
: fdisk /dev/sdb <<< $'nnpnnnntnbnpn'
, no?â Rastapopoulos
Oct 16 '17 at 10:22
1
1
@Rastapopoulos You're right. Thanks for your input.
â Kamil Maciorowski
Oct 16 '17 at 10:31
@Rastapopoulos You're right. Thanks for your input.
â Kamil Maciorowski
Oct 16 '17 at 10:31
add a comment |Â
up vote
0
down vote
Based on @KamilMaciorowski's answer (full credit to him), here is what I finally use:
sudo dd if=/dev/zero of=/dev/sdb bs=1M && sudo fdisk /dev/sdb <<< $'nnpnnnntnbnpnwn' && sudo mkfs.fat /dev/sdb1
add a comment |Â
up vote
0
down vote
Based on @KamilMaciorowski's answer (full credit to him), here is what I finally use:
sudo dd if=/dev/zero of=/dev/sdb bs=1M && sudo fdisk /dev/sdb <<< $'nnpnnnntnbnpnwn' && sudo mkfs.fat /dev/sdb1
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Based on @KamilMaciorowski's answer (full credit to him), here is what I finally use:
sudo dd if=/dev/zero of=/dev/sdb bs=1M && sudo fdisk /dev/sdb <<< $'nnpnnnntnbnpnwn' && sudo mkfs.fat /dev/sdb1
Based on @KamilMaciorowski's answer (full credit to him), here is what I finally use:
sudo dd if=/dev/zero of=/dev/sdb bs=1M && sudo fdisk /dev/sdb <<< $'nnpnnnntnbnpnwn' && sudo mkfs.fat /dev/sdb1
answered Oct 16 '17 at 23:19
Basj
6181731
6181731
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f398351%2fwipe-a-usb-flash-drive-and-recreate-a-filesystem%23new-answer', 'question_page');
);
Post as a guest
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
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
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