0

I am using these commands on command line:

sudo fdisk /dev/mmcblk1
p
d
w

sudo fdisk /dev/mmcblk1
n
(using all defaults)
w

Please is there any option how to automatize this task? Or how to use one liner for this (even for every fdisk command one liner, so two one liners in total)? Or maybe with python?

  • Note that sfdisk is intended for this sort of automation rather than fdisk. – psusi Nov 7 '18 at 17:40
2

Simply create a file (e.g. fdisk_cmds) that contains the commands, as for instance:

p
i
    # This is a blank line to select a default response
q

sudo fdisk /dev/mmcblk1 < fdisk_cmds
1

You can use a one liner command (bash):

(echo p; echo d; ... ; echo w) | fdisk /dev/mmcblk1

To set the default answer use echo "" , to answer Yes use echo "Y"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.