Home > Net >  'ip link set' command on multiple interfaces. Using brace expansion for enumerating interf
'ip link set' command on multiple interfaces. Using brace expansion for enumerating interf

Time:10-05

I'm trying to set the link up using 'ip link set' command. But I need to type this for each interface as below.

ip link set ens1f0 up
ip link set ens1f1 up
ip link set ens1f2 up
ip link set ens1f3 up

Is there a way to use brace expansion feature of bash so that this can be done in single command? Something like below

"ip link set ens1f"{0..3}" up"

I used the echo command to print the commands first and then copied the commands as below. But it is a two step process.

$ echo "ip link set ens1f"{0..3}" up;"
ip link set ens1f0 up; ip link set ens1f1 up; ip link set ens1f2 up; ip link set ens1f3 up;
$ ip link set ens1f0 up; ip link set ens1f1 up; ip link set ens1f2 up; ip link set ens1f3 up;

CodePudding user response:

Generates a list of interfaces' name with:

printf 'ens1f%d\n' {0..3}

Pipes this stream to xargs so it can execute the ip command with each interface name:

printf 'ens1f%d\n' {0..3} | xargs -I{} ip link set "{}" up
  • Related