Terminal command to show Network Interfaces that are NOT CONNECTED












2
















  • Using terminal mode I want to display the current network interfaces that are NOT CONNECTED on my computer.


  • I have used ifconfig to find the connected interfaces along with their IP-address but can't figure out how to display just those that are NOT CONNECTED.











share|improve this question

























  • ifconfig -a shows all network interfaces, connected or not

    – ivanivan
    Apr 6 '18 at 19:08






  • 4





    With "not connected" you mean "cable not plugged in" or "deactivated"?

    – Hauke Laging
    Apr 6 '18 at 19:58
















2
















  • Using terminal mode I want to display the current network interfaces that are NOT CONNECTED on my computer.


  • I have used ifconfig to find the connected interfaces along with their IP-address but can't figure out how to display just those that are NOT CONNECTED.











share|improve this question

























  • ifconfig -a shows all network interfaces, connected or not

    – ivanivan
    Apr 6 '18 at 19:08






  • 4





    With "not connected" you mean "cable not plugged in" or "deactivated"?

    – Hauke Laging
    Apr 6 '18 at 19:58














2












2








2









  • Using terminal mode I want to display the current network interfaces that are NOT CONNECTED on my computer.


  • I have used ifconfig to find the connected interfaces along with their IP-address but can't figure out how to display just those that are NOT CONNECTED.











share|improve this question

















  • Using terminal mode I want to display the current network interfaces that are NOT CONNECTED on my computer.


  • I have used ifconfig to find the connected interfaces along with their IP-address but can't figure out how to display just those that are NOT CONNECTED.








linux networking terminal






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 6 '18 at 20:06









guntbert

1,04511017




1,04511017










asked Apr 6 '18 at 19:01









nismoasfuhnismoasfuh

1313




1313













  • ifconfig -a shows all network interfaces, connected or not

    – ivanivan
    Apr 6 '18 at 19:08






  • 4





    With "not connected" you mean "cable not plugged in" or "deactivated"?

    – Hauke Laging
    Apr 6 '18 at 19:58



















  • ifconfig -a shows all network interfaces, connected or not

    – ivanivan
    Apr 6 '18 at 19:08






  • 4





    With "not connected" you mean "cable not plugged in" or "deactivated"?

    – Hauke Laging
    Apr 6 '18 at 19:58

















ifconfig -a shows all network interfaces, connected or not

– ivanivan
Apr 6 '18 at 19:08





ifconfig -a shows all network interfaces, connected or not

– ivanivan
Apr 6 '18 at 19:08




4




4





With "not connected" you mean "cable not plugged in" or "deactivated"?

– Hauke Laging
Apr 6 '18 at 19:58





With "not connected" you mean "cable not plugged in" or "deactivated"?

– Hauke Laging
Apr 6 '18 at 19:58










4 Answers
4






active

oldest

votes


















2














You can just do:



$ ip link show


for a list of interfaces including their status. You can filter results for devices that are not in use by piping grep DOWN after the ip command:



$ ip link show | grep DOWN





share|improve this answer





















  • 2





    Not connected is not the same as down.

    – Hauke Laging
    Apr 6 '18 at 19:57



















2














ip link show |
awk '/^[1-9]/ && $0 !~ "LOWER_UP" { inf=$2; sub(":","",inf); print inf; }' |
while read iface; do
[[ $(readlink /sys/class/net/$iface) =~ devices/virtual ]] || echo $iface
done


The first part (ip link show | awk) gets all the interfaces for which the L2 driver reports that they are connected. The second part discards all virtual interfaces because "not connected" does not mean much for them.






share|improve this answer































    1














    Using ifconfig (because that's the command you said you know how to use) and bash with diff and sed:



    diff <( ifconfig ) <( ifconfig -a ) | sed -nE 's/^> ([^[:blank:]]+).*/1/p'


    This will compare the output of ifconfig with that of ifconfig -a. From that output, any line starting with > (signifying that they are only in the ifconfig -a output) will be relating to interfaces that are not "UP". The sed expression parses out the interface names.



    The result will be a list of interfaces that are not up.





    The sed expression s/^> ([^[:blank:]]+).*/1/p:



    This is a substitution. It will match any line starting with > followed by a space. After that, it will capture any non-blank string of characters. This, with the rest of the line, is then replaced with the captured string of non-blank characters and the result is printed. The only lines that matches the regular expression in the output from diff are lines that mentions the interface name at the start of the line after > and space.






    share|improve this answer


























    • Thank you all! much appreciated! Kusalananda had the best answer for me.

      – nismoasfuh
      Apr 6 '18 at 21:05











    • Not connected is not the same as down. ifconfig is deprecated.

      – Pablo Bianchi
      3 hours ago



















    1














    You can check the state of the network interface from /sys/class/net/$interface/carrier file. (1 = connetcted , 0 = disconnected)



    To get the disconnected network interface:



    for i in $( ls /sys/class/net );do 
    if grep -q 0 /sys/class/net/$i/carrier; then
    echo $i;
    fi
    done





    share|improve this answer


























    • I'm not sure why I get errors like grep: /sys/class/net/lo/carrier: No such file or directory in all cases. Doesn't seem a quote/escape issue. Works outside the if.

      – Pablo Bianchi
      3 hours ago











    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%2f436050%2fterminal-command-to-show-network-interfaces-that-are-not-connected%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    You can just do:



    $ ip link show


    for a list of interfaces including their status. You can filter results for devices that are not in use by piping grep DOWN after the ip command:



    $ ip link show | grep DOWN





    share|improve this answer





















    • 2





      Not connected is not the same as down.

      – Hauke Laging
      Apr 6 '18 at 19:57
















    2














    You can just do:



    $ ip link show


    for a list of interfaces including their status. You can filter results for devices that are not in use by piping grep DOWN after the ip command:



    $ ip link show | grep DOWN





    share|improve this answer





















    • 2





      Not connected is not the same as down.

      – Hauke Laging
      Apr 6 '18 at 19:57














    2












    2








    2







    You can just do:



    $ ip link show


    for a list of interfaces including their status. You can filter results for devices that are not in use by piping grep DOWN after the ip command:



    $ ip link show | grep DOWN





    share|improve this answer















    You can just do:



    $ ip link show


    for a list of interfaces including their status. You can filter results for devices that are not in use by piping grep DOWN after the ip command:



    $ ip link show | grep DOWN






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Apr 6 '18 at 19:16

























    answered Apr 6 '18 at 19:11









    AlxsAlxs

    1,0911624




    1,0911624








    • 2





      Not connected is not the same as down.

      – Hauke Laging
      Apr 6 '18 at 19:57














    • 2





      Not connected is not the same as down.

      – Hauke Laging
      Apr 6 '18 at 19:57








    2




    2





    Not connected is not the same as down.

    – Hauke Laging
    Apr 6 '18 at 19:57





    Not connected is not the same as down.

    – Hauke Laging
    Apr 6 '18 at 19:57













    2














    ip link show |
    awk '/^[1-9]/ && $0 !~ "LOWER_UP" { inf=$2; sub(":","",inf); print inf; }' |
    while read iface; do
    [[ $(readlink /sys/class/net/$iface) =~ devices/virtual ]] || echo $iface
    done


    The first part (ip link show | awk) gets all the interfaces for which the L2 driver reports that they are connected. The second part discards all virtual interfaces because "not connected" does not mean much for them.






    share|improve this answer




























      2














      ip link show |
      awk '/^[1-9]/ && $0 !~ "LOWER_UP" { inf=$2; sub(":","",inf); print inf; }' |
      while read iface; do
      [[ $(readlink /sys/class/net/$iface) =~ devices/virtual ]] || echo $iface
      done


      The first part (ip link show | awk) gets all the interfaces for which the L2 driver reports that they are connected. The second part discards all virtual interfaces because "not connected" does not mean much for them.






      share|improve this answer


























        2












        2








        2







        ip link show |
        awk '/^[1-9]/ && $0 !~ "LOWER_UP" { inf=$2; sub(":","",inf); print inf; }' |
        while read iface; do
        [[ $(readlink /sys/class/net/$iface) =~ devices/virtual ]] || echo $iface
        done


        The first part (ip link show | awk) gets all the interfaces for which the L2 driver reports that they are connected. The second part discards all virtual interfaces because "not connected" does not mean much for them.






        share|improve this answer













        ip link show |
        awk '/^[1-9]/ && $0 !~ "LOWER_UP" { inf=$2; sub(":","",inf); print inf; }' |
        while read iface; do
        [[ $(readlink /sys/class/net/$iface) =~ devices/virtual ]] || echo $iface
        done


        The first part (ip link show | awk) gets all the interfaces for which the L2 driver reports that they are connected. The second part discards all virtual interfaces because "not connected" does not mean much for them.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 6 '18 at 19:56









        Hauke LagingHauke Laging

        56k1285135




        56k1285135























            1














            Using ifconfig (because that's the command you said you know how to use) and bash with diff and sed:



            diff <( ifconfig ) <( ifconfig -a ) | sed -nE 's/^> ([^[:blank:]]+).*/1/p'


            This will compare the output of ifconfig with that of ifconfig -a. From that output, any line starting with > (signifying that they are only in the ifconfig -a output) will be relating to interfaces that are not "UP". The sed expression parses out the interface names.



            The result will be a list of interfaces that are not up.





            The sed expression s/^> ([^[:blank:]]+).*/1/p:



            This is a substitution. It will match any line starting with > followed by a space. After that, it will capture any non-blank string of characters. This, with the rest of the line, is then replaced with the captured string of non-blank characters and the result is printed. The only lines that matches the regular expression in the output from diff are lines that mentions the interface name at the start of the line after > and space.






            share|improve this answer


























            • Thank you all! much appreciated! Kusalananda had the best answer for me.

              – nismoasfuh
              Apr 6 '18 at 21:05











            • Not connected is not the same as down. ifconfig is deprecated.

              – Pablo Bianchi
              3 hours ago
















            1














            Using ifconfig (because that's the command you said you know how to use) and bash with diff and sed:



            diff <( ifconfig ) <( ifconfig -a ) | sed -nE 's/^> ([^[:blank:]]+).*/1/p'


            This will compare the output of ifconfig with that of ifconfig -a. From that output, any line starting with > (signifying that they are only in the ifconfig -a output) will be relating to interfaces that are not "UP". The sed expression parses out the interface names.



            The result will be a list of interfaces that are not up.





            The sed expression s/^> ([^[:blank:]]+).*/1/p:



            This is a substitution. It will match any line starting with > followed by a space. After that, it will capture any non-blank string of characters. This, with the rest of the line, is then replaced with the captured string of non-blank characters and the result is printed. The only lines that matches the regular expression in the output from diff are lines that mentions the interface name at the start of the line after > and space.






            share|improve this answer


























            • Thank you all! much appreciated! Kusalananda had the best answer for me.

              – nismoasfuh
              Apr 6 '18 at 21:05











            • Not connected is not the same as down. ifconfig is deprecated.

              – Pablo Bianchi
              3 hours ago














            1












            1








            1







            Using ifconfig (because that's the command you said you know how to use) and bash with diff and sed:



            diff <( ifconfig ) <( ifconfig -a ) | sed -nE 's/^> ([^[:blank:]]+).*/1/p'


            This will compare the output of ifconfig with that of ifconfig -a. From that output, any line starting with > (signifying that they are only in the ifconfig -a output) will be relating to interfaces that are not "UP". The sed expression parses out the interface names.



            The result will be a list of interfaces that are not up.





            The sed expression s/^> ([^[:blank:]]+).*/1/p:



            This is a substitution. It will match any line starting with > followed by a space. After that, it will capture any non-blank string of characters. This, with the rest of the line, is then replaced with the captured string of non-blank characters and the result is printed. The only lines that matches the regular expression in the output from diff are lines that mentions the interface name at the start of the line after > and space.






            share|improve this answer















            Using ifconfig (because that's the command you said you know how to use) and bash with diff and sed:



            diff <( ifconfig ) <( ifconfig -a ) | sed -nE 's/^> ([^[:blank:]]+).*/1/p'


            This will compare the output of ifconfig with that of ifconfig -a. From that output, any line starting with > (signifying that they are only in the ifconfig -a output) will be relating to interfaces that are not "UP". The sed expression parses out the interface names.



            The result will be a list of interfaces that are not up.





            The sed expression s/^> ([^[:blank:]]+).*/1/p:



            This is a substitution. It will match any line starting with > followed by a space. After that, it will capture any non-blank string of characters. This, with the rest of the line, is then replaced with the captured string of non-blank characters and the result is printed. The only lines that matches the regular expression in the output from diff are lines that mentions the interface name at the start of the line after > and space.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Apr 6 '18 at 20:05

























            answered Apr 6 '18 at 19:18









            KusalanandaKusalananda

            124k16233384




            124k16233384













            • Thank you all! much appreciated! Kusalananda had the best answer for me.

              – nismoasfuh
              Apr 6 '18 at 21:05











            • Not connected is not the same as down. ifconfig is deprecated.

              – Pablo Bianchi
              3 hours ago



















            • Thank you all! much appreciated! Kusalananda had the best answer for me.

              – nismoasfuh
              Apr 6 '18 at 21:05











            • Not connected is not the same as down. ifconfig is deprecated.

              – Pablo Bianchi
              3 hours ago

















            Thank you all! much appreciated! Kusalananda had the best answer for me.

            – nismoasfuh
            Apr 6 '18 at 21:05





            Thank you all! much appreciated! Kusalananda had the best answer for me.

            – nismoasfuh
            Apr 6 '18 at 21:05













            Not connected is not the same as down. ifconfig is deprecated.

            – Pablo Bianchi
            3 hours ago





            Not connected is not the same as down. ifconfig is deprecated.

            – Pablo Bianchi
            3 hours ago











            1














            You can check the state of the network interface from /sys/class/net/$interface/carrier file. (1 = connetcted , 0 = disconnected)



            To get the disconnected network interface:



            for i in $( ls /sys/class/net );do 
            if grep -q 0 /sys/class/net/$i/carrier; then
            echo $i;
            fi
            done





            share|improve this answer


























            • I'm not sure why I get errors like grep: /sys/class/net/lo/carrier: No such file or directory in all cases. Doesn't seem a quote/escape issue. Works outside the if.

              – Pablo Bianchi
              3 hours ago
















            1














            You can check the state of the network interface from /sys/class/net/$interface/carrier file. (1 = connetcted , 0 = disconnected)



            To get the disconnected network interface:



            for i in $( ls /sys/class/net );do 
            if grep -q 0 /sys/class/net/$i/carrier; then
            echo $i;
            fi
            done





            share|improve this answer


























            • I'm not sure why I get errors like grep: /sys/class/net/lo/carrier: No such file or directory in all cases. Doesn't seem a quote/escape issue. Works outside the if.

              – Pablo Bianchi
              3 hours ago














            1












            1








            1







            You can check the state of the network interface from /sys/class/net/$interface/carrier file. (1 = connetcted , 0 = disconnected)



            To get the disconnected network interface:



            for i in $( ls /sys/class/net );do 
            if grep -q 0 /sys/class/net/$i/carrier; then
            echo $i;
            fi
            done





            share|improve this answer















            You can check the state of the network interface from /sys/class/net/$interface/carrier file. (1 = connetcted , 0 = disconnected)



            To get the disconnected network interface:



            for i in $( ls /sys/class/net );do 
            if grep -q 0 /sys/class/net/$i/carrier; then
            echo $i;
            fi
            done






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 9 mins ago









            Pablo Bianchi

            491511




            491511










            answered Apr 6 '18 at 20:46









            GAD3RGAD3R

            25.7k1750107




            25.7k1750107













            • I'm not sure why I get errors like grep: /sys/class/net/lo/carrier: No such file or directory in all cases. Doesn't seem a quote/escape issue. Works outside the if.

              – Pablo Bianchi
              3 hours ago



















            • I'm not sure why I get errors like grep: /sys/class/net/lo/carrier: No such file or directory in all cases. Doesn't seem a quote/escape issue. Works outside the if.

              – Pablo Bianchi
              3 hours ago

















            I'm not sure why I get errors like grep: /sys/class/net/lo/carrier: No such file or directory in all cases. Doesn't seem a quote/escape issue. Works outside the if.

            – Pablo Bianchi
            3 hours ago





            I'm not sure why I get errors like grep: /sys/class/net/lo/carrier: No such file or directory in all cases. Doesn't seem a quote/escape issue. Works outside the if.

            – Pablo Bianchi
            3 hours ago


















            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%2f436050%2fterminal-command-to-show-network-interfaces-that-are-not-connected%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







            Popular posts from this blog

            CARDNET

            Boot-repair Failure: Unable to locate package grub-common:i386

            Aws NAT - Aws IGW- Aws router