How to find the names of partitions of a given block device? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election Results Why I closed the “Why is Kali so hard” questionHow to get size of a block special file?How to find out easily whether a block device (or a part of it) is mounted somehowHow to change block device names, e.g. /dev/sdc to /dev/sdb?How to recycle USB device names on Linux after forced removalGet block device parentHow to get block device name from partition device name?How to determine what block device (/dev/sd* or UUID) a particular file is onGiven a block partition, look up open LUKS deviceDoes output redirection to a block device overwrite bytes or whole blocks?Given a block device, how to detect if names of partitions must contain “p”?
What to do with chalk when deepwater soloing?
String `!23` is replaced with `docker` in command line
Book where humans were engineered with genes from animal species to survive hostile planets
Why is my conclusion inconsistent with the van't Hoff equation?
Why is "Consequences inflicted." not a sentence?
Storing hydrofluoric acid before the invention of plastics
Why light coming from distant stars is not discreet?
Why am I getting the error "non-boolean type specified in a context where a condition is expected" for this request?
Why did the rest of the Eastern Bloc not invade Yugoslavia?
How to align text above triangle figure
What is Arya's weapon design?
Overriding an object in memory with placement new
How to find all the available tools in mac terminal?
How to call a function with default parameter through a pointer to function that is the return of another function?
How to deal with a team lead who never gives me credit?
Withdrew £2800, but only £2000 shows as withdrawn on online banking; what are my obligations?
How does debian/ubuntu knows a package has a updated version
Can a USB port passively 'listen only'?
Generate an RGB colour grid
How come Sam didn't become Lord of Horn Hill?
Why are Kinder Surprise Eggs illegal in the USA?
Using audio cues to encourage good posture
Why do we bend a book to keep it straight?
What's the purpose of writing one's academic biography in the third person?
How to find the names of partitions of a given block device?
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionHow to get size of a block special file?How to find out easily whether a block device (or a part of it) is mounted somehowHow to change block device names, e.g. /dev/sdc to /dev/sdb?How to recycle USB device names on Linux after forced removalGet block device parentHow to get block device name from partition device name?How to determine what block device (/dev/sd* or UUID) a particular file is onGiven a block partition, look up open LUKS deviceDoes output redirection to a block device overwrite bytes or whole blocks?Given a block device, how to detect if names of partitions must contain “p”?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
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
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
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
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
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
edited 11 hours ago
Rui F Ribeiro
42.1k1484142
42.1k1484142
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
-block-device, linux, linux-kernel, partition