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

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












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



            Hope this helps!






            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



                    Hope this helps!






                    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



                    Hope this helps!






                    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



                    Hope this helps!






                    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



                    Hope this helps!







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    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