ifconfig -a lists all network interfaces. I need to run
sudo ifconfig <iface name> down for each interface listed by the command. What is the ideal way to implement this inside a shell script?
You can find the name of each network interface listed by
ifconfig -a in the directory /sys/class/net, which is populated by the kernel itself. Since the name of each directory in
/sys/class/net is the actual name of the interface, you can loop over the files.
for intf in /sys/class/net/*; do sudo ifconfig `basename $intf` down done