How to find the names of partitions of a given block device?

Clash Royale CLAN TAG#URR8PPP
Given a block device (e.g, /dev/sda), how to determine the names of its partitions (if any) in a script (i.e. without user interaction)?
linux linux-kernel partition block-device
add a comment |
Given a block device (e.g, /dev/sda), how to determine the names of its partitions (if any) in a script (i.e. without user interaction)?
linux linux-kernel partition block-device
add a comment |
Given a block device (e.g, /dev/sda), how to determine the names of its partitions (if any) in a script (i.e. without user interaction)?
linux linux-kernel partition block-device
Given a block device (e.g, /dev/sda), how to determine the names of its partitions (if any) in a script (i.e. without user interaction)?
linux linux-kernel partition block-device
linux linux-kernel partition block-device
edited Feb 19 at 11:32
stefanct
asked Feb 15 at 14:48
stefanctstefanct
1407
1407
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
lsblk prints out all related block devices. This includes the partitions of said device. Since it of course includes the device itself and lsblk does not allow for excluding specific devices the example solution below simply uses inverted grep:
lsblk -o KNAME -n /dev/mmcblk0 | grep -v "^mmcblk0$"
For full paths (which also simplifies the generation of the grep string) one can use -p, e.g.:
lsblk -po KNAME -n /dev/mmcblk0 | grep -v "^/dev/mmcblk0$"
add a comment |
There are a couple of tools which you can use for this. One of the tools which I tend to use a lot is fdisk. fdisk is something which will list the partitions of your block device and also state the exact sizes for you. fdisk is quite a versatile program which can also modify the internal properties of your partitions in terms of storage so be very careful using it.
In the case of listing a partition you simply want to execute the following command:fdisk -l <name of block device>. From this point you're then able to see the exact sizes, name and type of the partitions you seek. If you would like to use fdisk further for other uses relating to the hard disk then use the man command to open the manual page for fdisk:
man fdisk
Hope this helps!
I phrased my question not carefully enough and have edited it now. I meant automatically within a script and without any user interaction. There are lots of way for finding this out interactively in Linux.
– stefanct
Feb 19 at 11:42
In this case you should consult the bash programming language. You will be able to use Linux commands in a programmable environment and you won't require any further user interaction. I understand what you're asking now. Please feel free to write your script and message me if you would like a hand or just general feedback
– A.Hussain
Feb 19 at 12:19
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%2f500889%2fhow-to-find-the-names-of-partitions-of-a-given-block-device%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
lsblk prints out all related block devices. This includes the partitions of said device. Since it of course includes the device itself and lsblk does not allow for excluding specific devices the example solution below simply uses inverted grep:
lsblk -o KNAME -n /dev/mmcblk0 | grep -v "^mmcblk0$"
For full paths (which also simplifies the generation of the grep string) one can use -p, e.g.:
lsblk -po KNAME -n /dev/mmcblk0 | grep -v "^/dev/mmcblk0$"
add a comment |
lsblk prints out all related block devices. This includes the partitions of said device. Since it of course includes the device itself and lsblk does not allow for excluding specific devices the example solution below simply uses inverted grep:
lsblk -o KNAME -n /dev/mmcblk0 | grep -v "^mmcblk0$"
For full paths (which also simplifies the generation of the grep string) one can use -p, e.g.:
lsblk -po KNAME -n /dev/mmcblk0 | grep -v "^/dev/mmcblk0$"
add a comment |
lsblk prints out all related block devices. This includes the partitions of said device. Since it of course includes the device itself and lsblk does not allow for excluding specific devices the example solution below simply uses inverted grep:
lsblk -o KNAME -n /dev/mmcblk0 | grep -v "^mmcblk0$"
For full paths (which also simplifies the generation of the grep string) one can use -p, e.g.:
lsblk -po KNAME -n /dev/mmcblk0 | grep -v "^/dev/mmcblk0$"
lsblk prints out all related block devices. This includes the partitions of said device. Since it of course includes the device itself and lsblk does not allow for excluding specific devices the example solution below simply uses inverted grep:
lsblk -o KNAME -n /dev/mmcblk0 | grep -v "^mmcblk0$"
For full paths (which also simplifies the generation of the grep string) one can use -p, e.g.:
lsblk -po KNAME -n /dev/mmcblk0 | grep -v "^/dev/mmcblk0$"
edited Feb 15 at 15:01
answered Feb 15 at 14:48
stefanctstefanct
1407
1407
add a comment |
add a comment |
There are a couple of tools which you can use for this. One of the tools which I tend to use a lot is fdisk. fdisk is something which will list the partitions of your block device and also state the exact sizes for you. fdisk is quite a versatile program which can also modify the internal properties of your partitions in terms of storage so be very careful using it.
In the case of listing a partition you simply want to execute the following command:fdisk -l <name of block device>. From this point you're then able to see the exact sizes, name and type of the partitions you seek. If you would like to use fdisk further for other uses relating to the hard disk then use the man command to open the manual page for fdisk:
man fdisk
Hope this helps!
I phrased my question not carefully enough and have edited it now. I meant automatically within a script and without any user interaction. There are lots of way for finding this out interactively in Linux.
– stefanct
Feb 19 at 11:42
In this case you should consult the bash programming language. You will be able to use Linux commands in a programmable environment and you won't require any further user interaction. I understand what you're asking now. Please feel free to write your script and message me if you would like a hand or just general feedback
– A.Hussain
Feb 19 at 12:19
add a comment |
There are a couple of tools which you can use for this. One of the tools which I tend to use a lot is fdisk. fdisk is something which will list the partitions of your block device and also state the exact sizes for you. fdisk is quite a versatile program which can also modify the internal properties of your partitions in terms of storage so be very careful using it.
In the case of listing a partition you simply want to execute the following command:fdisk -l <name of block device>. From this point you're then able to see the exact sizes, name and type of the partitions you seek. If you would like to use fdisk further for other uses relating to the hard disk then use the man command to open the manual page for fdisk:
man fdisk
Hope this helps!
I phrased my question not carefully enough and have edited it now. I meant automatically within a script and without any user interaction. There are lots of way for finding this out interactively in Linux.
– stefanct
Feb 19 at 11:42
In this case you should consult the bash programming language. You will be able to use Linux commands in a programmable environment and you won't require any further user interaction. I understand what you're asking now. Please feel free to write your script and message me if you would like a hand or just general feedback
– A.Hussain
Feb 19 at 12:19
add a comment |
There are a couple of tools which you can use for this. One of the tools which I tend to use a lot is fdisk. fdisk is something which will list the partitions of your block device and also state the exact sizes for you. fdisk is quite a versatile program which can also modify the internal properties of your partitions in terms of storage so be very careful using it.
In the case of listing a partition you simply want to execute the following command:fdisk -l <name of block device>. From this point you're then able to see the exact sizes, name and type of the partitions you seek. If you would like to use fdisk further for other uses relating to the hard disk then use the man command to open the manual page for fdisk:
man fdisk
Hope this helps!
There are a couple of tools which you can use for this. One of the tools which I tend to use a lot is fdisk. fdisk is something which will list the partitions of your block device and also state the exact sizes for you. fdisk is quite a versatile program which can also modify the internal properties of your partitions in terms of storage so be very careful using it.
In the case of listing a partition you simply want to execute the following command:fdisk -l <name of block device>. From this point you're then able to see the exact sizes, name and type of the partitions you seek. If you would like to use fdisk further for other uses relating to the hard disk then use the man command to open the manual page for fdisk:
man fdisk
Hope this helps!
answered Feb 19 at 10:52
A.HussainA.Hussain
12
12
I phrased my question not carefully enough and have edited it now. I meant automatically within a script and without any user interaction. There are lots of way for finding this out interactively in Linux.
– stefanct
Feb 19 at 11:42
In this case you should consult the bash programming language. You will be able to use Linux commands in a programmable environment and you won't require any further user interaction. I understand what you're asking now. Please feel free to write your script and message me if you would like a hand or just general feedback
– A.Hussain
Feb 19 at 12:19
add a comment |
I phrased my question not carefully enough and have edited it now. I meant automatically within a script and without any user interaction. There are lots of way for finding this out interactively in Linux.
– stefanct
Feb 19 at 11:42
In this case you should consult the bash programming language. You will be able to use Linux commands in a programmable environment and you won't require any further user interaction. I understand what you're asking now. Please feel free to write your script and message me if you would like a hand or just general feedback
– A.Hussain
Feb 19 at 12:19
I phrased my question not carefully enough and have edited it now. I meant automatically within a script and without any user interaction. There are lots of way for finding this out interactively in Linux.
– stefanct
Feb 19 at 11:42
I phrased my question not carefully enough and have edited it now. I meant automatically within a script and without any user interaction. There are lots of way for finding this out interactively in Linux.
– stefanct
Feb 19 at 11:42
In this case you should consult the bash programming language. You will be able to use Linux commands in a programmable environment and you won't require any further user interaction. I understand what you're asking now. Please feel free to write your script and message me if you would like a hand or just general feedback
– A.Hussain
Feb 19 at 12:19
In this case you should consult the bash programming language. You will be able to use Linux commands in a programmable environment and you won't require any further user interaction. I understand what you're asking now. Please feel free to write your script and message me if you would like a hand or just general feedback
– A.Hussain
Feb 19 at 12:19
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%2f500889%2fhow-to-find-the-names-of-partitions-of-a-given-block-device%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