Posted: . At: 8:41 PM. This was 2 years ago. Post ID: 15726
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


How to print your IP address with Bash on Mac OSX in the terminal app.


This one-liner will print the current LAN IP address of a machine running Macintosh OSX.

jason@. PWD: ~. -bash. 3.2.57. 10 $> ifconfig | grep "inet " | awk 'FNR==2{print $2}'
192.168.1.2

This is 10.14.2 (18C54), but this command should still work on a more modern Mac.

The FNR==2 statement in Awk will print only the second line of output and this makes this a simpler bash one-liner.

So this is how to print only the 2nd column of text and only the second line of the text output.

awk 'FNR==2{print $2}'

A very useful trick to know when using Linux or UNIX. Or course I am using UNIX at the moment, this is fine though, it works perfectly.

jason@. PWD: ~. -bash. 3.2.57. 11 $> uname -a
Darwin deusexmachina.local 18.2.0 Darwin Kernel Version 18.2.0: Mon Nov 12 20:24:46 PST 2018; root:xnu-4903.231.4~2/RELEASE_X86_64 x86_64

This works as well.

jason@. PWD: ~. -bash. 3.2.57. 12 $> ifcoifconfig | grep "inet " | awk 'NR==2{print $2}'
192.168.1.2

This is one character shorter.

But still works very well for getting the information you seek. This is how to find out the Mac OSX release version from the terminal.

jason@. PWD: ~. -bash. 3.2.57. 22 $> sw_vers
ProductName:	Mac OS X
ProductVersion:	10.14.2
BuildVersion:	18C54

Very simple to use.

Use the softwareupdate utility to find any pending updates.

jason@. PWD: ~. -bash. 3.2.57. 24 $> softwareupdate -l
Software Update Tool
 
Finding available software
Software Update found the following new or updated software:
   * Device Support Update- 
	Device Support Update ( ), 191029K [recommended]
   * iTunes Device Support Update- 
	iTunes Device Support Update ( ), 105805K [recommended] [restart]
   * Command Line Tools (macOS Mojave version 10.14) for Xcode-10.3
	Command Line Tools (macOS Mojave version 10.14) for Xcode (10.3), 199250K [recommended]
   * macOS 10.14.6 Update- 
	macOS 10.14.6 Update ( ), 2545010K [recommended] [restart]

This command lists all pending updates.

The softwareupdate -i -a command will then download and install all pending updates.

jason@. PWD: ~. -bash. 3.2.57. 27 $> sudo softwareupdate -i -a
Software Update Tool
 
Finding available software
 
Downloaded Command Line Tools (macOS Mojave version 10.14) for Xcode
Downloaded iTunes Device Support Update
Downloading macOS 10.14.6 Update
Downloading Device Support Update
Downloaded Device Support Update
Downloaded macOS 10.14.6 Update
Installing macOS 10.14.6 Update, Device Support Update, Command Line Tools (macOS Mojave version 10.14) for Xcode, iTunes Device Support Update
Done with Device Support Update
Done with Command Line Tools (macOS Mojave version 10.14) for Xcode
Done with iTunes Device Support Update
Done.
 
You have installed one or more updates that requires that you restart your computer.
Please restart immediately.
To automate the restart process with softwareupdate(8), use --restart.

This is a very useful way to download and install updates on a Macintosh OSX machine, and I have only just found out about this. But I just had to share this as it is very useful. Finding a command-line approach to a certain problem is something I enjoy, and this is one very useful utility, all I need to do is wait for the updates to finish and then I am fine. But UNIX always has good solutions to various problems and Macintosh OSX is not left out.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.