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?

1
  • "host" is already occupied, but sure, by editing your ~/.bashrc search for it on askubuntu should give you plenty of results. Oct 30, 2014 at 10:44

1 Answer 1

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
  • 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 Oct 30, 2014 at 11:29

Not the answer you're looking for? Browse other questions tagged .