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;








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)?










share|improve this question






























    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)?










    share|improve this question


























      0












      0








      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)?










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 19 at 11:32







      stefanct

















      asked Feb 15 at 14:48









      stefanctstefanct

      1407




      1407




















          2 Answers
          2






          active

          oldest

          votes


















          0














          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$"





          share|improve this answer
































            0














            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






            share|improve this answer

























            • 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











            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
            );



            );













            draft saved

            draft discarded


















            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









            0














            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$"





            share|improve this answer





























              0














              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$"





              share|improve this answer



























                0












                0








                0







                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$"





                share|improve this answer















                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$"






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Feb 15 at 15:01

























                answered Feb 15 at 14:48









                stefanctstefanct

                1407




                1407























                    0














                    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






                    share|improve this answer

























                    • 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















                    0














                    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






                    share|improve this answer

























                    • 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













                    0












                    0








                    0







                    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






                    share|improve this answer















                    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







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    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

















                    • 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

















                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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

                    Popular posts from this blog

                    Mobil Contents History Mobil brands Former Mobil brands Lukoil transaction Mobil UK Mobil Australia Mobil New Zealand Mobil Greece Mobil in Japan Mobil in Canada Mobil Egypt See also References External links Navigation menuwww.mobil.com"Mobil Corporation"the original"Our Houston campus""Business & Finance: Socony-Vacuum Corp.""Popular Mechanics""Lubrite Technologies""Exxon Mobil campus 'clearly happening'""Toledo Blade - Google News Archive Search""The Lion and the Moose - How 2 Executives Pulled off the Biggest Merger Ever""ExxonMobil Press Release""Lubricants""Archived copy"the original"Mobil 1™ and Mobil Super™ motor oil and synthetic motor oil - Mobil™ Motor Oils""Mobil Delvac""Mobil Industrial website""The State of Competition in Gasoline Marketing: The Effects of Refiner Operations at Retail""Mobil Travel Guide to become Forbes Travel Guide""Hotel Rankings: Forbes Merges with Mobil"the original"Jamieson oil industry history""Mobil news""Caltex pumps for control""Watchdog blocks Caltex bid""Exxon Mobil sells service station network""Mobil Oil New Zealand Limited is New Zealand's oldest oil company, with predecessor companies having first established a presence in the country in 1896""ExxonMobil subsidiaries have a business history in New Zealand stretching back more than 120 years. We are involved in petroleum refining and distribution and the marketing of fuels, lubricants and chemical products""Archived copy"the original"Exxon Mobil to Sell Its Japanese Arm for $3.9 Billion""Gas station merger will end Esso and Mobil's long run in Japan""Esso moves to affiliate itself with PC Optimum, no longer Aeroplan, in loyalty point switch""Mobil brand of gas stations to launch in Canada after deal for 213 Loblaws-owned locations""Mobil Nears Completion of Rebranding 200 Loblaw Gas Stations""Learn about ExxonMobil's operations in Egypt""Petrol and Diesel Service Stations in Egypt - Mobil"Official websiteExxon Mobil corporate websiteMobil Industrial official websiteeeeeeeeDA04275022275790-40000 0001 0860 5061n82045453134887257134887257

                    Frič See also Navigation menuinternal link

                    Identify plant with long narrow paired leaves and reddish stems Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?What is this plant with long sharp leaves? Is it a weed?What is this 3ft high, stalky plant, with mid sized narrow leaves?What is this young shrub with opposite ovate, crenate leaves and reddish stems?What is this plant with large broad serrated leaves?Identify this upright branching weed with long leaves and reddish stemsPlease help me identify this bulbous plant with long, broad leaves and white flowersWhat is this small annual with narrow gray/green leaves and rust colored daisy-type flowers?What is this chilli plant?Does anyone know what type of chilli plant this is?Help identify this plant