Terminal command to show Network Interfaces that are NOT CONNECTED
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
add a comment |
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
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
add a comment |
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
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
linux networking terminal
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
add a comment |
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
add a comment |
4 Answers
4
active
oldest
votes
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
2
Not connected is not the same as down.
– Hauke Laging
Apr 6 '18 at 19:57
add a comment |
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.
add a comment |
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.
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
add a comment |
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
I'm not sure why I get errors likegrep: /sys/class/net/lo/carrier: No such file or directory
in all cases. Doesn't seem a quote/escape issue. Works outside theif
.
– Pablo Bianchi
3 hours ago
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%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
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
2
Not connected is not the same as down.
– Hauke Laging
Apr 6 '18 at 19:57
add a comment |
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
2
Not connected is not the same as down.
– Hauke Laging
Apr 6 '18 at 19:57
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Apr 6 '18 at 19:56
Hauke LagingHauke Laging
56k1285135
56k1285135
add a comment |
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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
I'm not sure why I get errors likegrep: /sys/class/net/lo/carrier: No such file or directory
in all cases. Doesn't seem a quote/escape issue. Works outside theif
.
– Pablo Bianchi
3 hours ago
add a comment |
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
I'm not sure why I get errors likegrep: /sys/class/net/lo/carrier: No such file or directory
in all cases. Doesn't seem a quote/escape issue. Works outside theif
.
– Pablo Bianchi
3 hours ago
add a comment |
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
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
edited 12 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 likegrep: /sys/class/net/lo/carrier: No such file or directory
in all cases. Doesn't seem a quote/escape issue. Works outside theif
.
– Pablo Bianchi
3 hours ago
add a comment |
I'm not sure why I get errors likegrep: /sys/class/net/lo/carrier: No such file or directory
in all cases. Doesn't seem a quote/escape issue. Works outside theif
.
– 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
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%2f436050%2fterminal-command-to-show-network-interfaces-that-are-not-connected%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
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