0

Let's say I have this command:

/sbin/ifconfig|grep inet|head -1|sed 's/\:/ /'|awk '{print $3}'

Is it possible to shorten this to let's say writing host in the command line?

funguy
  • 493
  • 4
  • 6
  • "host" is already occupied, but sure, by editing your ~/.bashrc search for it on askubuntu should give you plenty of results. – Jacob Vlijm Oct 30 '14 at 10:44

1 Answers1

1

Yes, you can create shell alias, which is exactly what you need:

$ alias mycmd="/sbin/ifconfig|grep inet|head -1|sed 's/\:/ /'|awk '{print $3}'"

You probably want to have above alias permanent. To achieve this, add the above alias command to the ~/.bashrc file.

  • 1
    It will likely be necessary to escape the $ in the awk field i.e. awk '{print \$3}'" to prevent the shell from expanding it during alias creation – steeldriver Oct 30 '14 at 11:29