To quickly retrieve the IP address of the router you are connected through, type the following at the command line:
netstat -rn |grep default
The result will look something like this, showing the router IP directly after “default”:
default 192.168.1.1 UGSc 108 0 en0
netstat will work for both wired and wireless connections, the difference of which will be shown as the interface. These are typically en0 and en1, though the port interfaces will vary slightly with Macs that don’t include ethernet ports or AirPort wireless card, and for Macs with only one form of network connectivity it will almost always be en0.
Tired of bash? Prefer ksh, tcsh, or sh? You can quickly change the default shell in Terminal app, in addition to changing a users default login shell for when logging in remotely with SSH or otherwise. Here’s how to do both.
Change Terminal Apps Default Shell in OS X
Open Preferences from the Terminal menu, click the “Startup” tab
Under “Shells open with” choose “Command (complete path)” and set the new shell
Change a User Default Login Shell in Mac OS X
You can also change the default shell through the command line itself using the chsh command, this will be necessary if you want the default shell to be different when logging in with SSH or telnet. You’ll need to authenticate each change:
ksh: chsh -s /bin/ksh
tcsh: chsh -s /bin/tcsh
bash (default): chsh -s /bin/bash
sh: chsh -s /bin/sh
We covered the first part of this years ago and it hasn’t changed since, even with OS X Lion and OS X Mountain Lion.
You can create ISO images from any source disk or data by using the command line in Mac OS X. This isn’t too different than burning them through Terminal, and you can use either the hdiutil tool or dd command.
While the command line is generally reserved for advanced users, using it to create ISO’s isn’t too complicated and will save you the hassle of having to download any third party apps. If you’re new to the Terminal, remember that dragging & dropping files into the Terminal window will print their full path, making it easy to point to source files and preventing any navigation through the command line.
Creating an ISO with hdiutil
The most reliable method is uses hdiutil, here is the syntax:
The -joliet flag is necessary to make the iso fully compatible with Windows and other OS’s, though if your only requirement is to use the iso on a Mac you can leave it off.
Making an ISO with dd
Another approach is by switching around a previously discussed dd command, which makes it go from burning an image to creating an image. This may not be as reliable and it requires additional steps, so use dd only if you have a good reason not to use the primary hdiutil method.
Use the ‘diskutil list’ command to discover the disks identifier that you will need to make an ISO with dd from.
dd if=/dev/dvd of=/destination/path/dvd.iso
dd is often faster than hdiutil, but it’s definitely for more advanced users.
Converting Other Disk Image Formats to ISO
You can also convert other disk images like cdr, dmg, and nero images to ISO, read more about that here if interested.
The most straight forward way to burn an ISO from a Mac is using Disk Utility, but you can also burn ISO’s and disk images directly from the command line with the help of a tool called ‘dd’.
dd can be advantageous for several reasons. For one, the command line aspect makes it easy to use through a remote SSH connection, but perhaps more useful is dd’s low-level functionality which is generally faster than alternatives and could circumvent some error messages.
Because this is a command line tool it should be considered mostly for advanced users, and although this is written with Mac OS X in mind it should work with Linux as well, with the exception of the diskutil command. As usual, be certain that all syntax is entered properly to avoid potential problems, and if in doubt, just stick with a simpler method from the GUI.
Burn an ISO from the Command Line with dd
The first thing you’ll need to do is find the disk or drive from the command line:
diskutil list
Locate the name of the destination drive in the mounted drives list and make note of its “IDENTIFIER” code, this should be something like “disk1s1″ but it will likely be unique to your machine.
Using the identifier you just found, unmount the disk but do not disconnect it from the Mac:
sudo umount /dev/disk1s1
Enter the administrator password when requested to complete unmount.
Burning a disk image using the command line tool ‘dd’ uses the following syntax:
dd if=/path/to/image.iso of=/dev/disk1s1
For example, to burn an image located on the desktop of user “Will” called “OSXMountainGorilla.iso” the command would be:
You will notice that dd does not give you updates or a status bar, but when the command is finished running you will be returned to the standard terminal prompt.
Any disk image should work as dd is not limited to ISO. You could use this tool to make bootable Mac OS installation drives as well, including for for OS X Mountain Lion and OS X Lion.
A MAC address is a unique identification number assigned to network interfaces, these can be attached to physical hardware like NIC and Wi-Fi cards or assigned to virtual machines. On some occasions, you’ll need to change a MAC address to another ID.
We’ve received a few questions about this recently because the process of changing (sometimes called spoofing) these addresses has changed slightly from version to version in Mac OS X. With that in mind, we will show you how to change a MAC address in the latest versions of OS X 10.7 and 10.8. Launch the Terminal found within /Applications/Utilities/ to get started.
Get a New MAC Address
The first thing you’ll want to do is retrieve the intended MAC address. If you have one in mind then use that, but if you aren’t trying to spoof a specific address and just need a random one, use the following command to generate one with openssl:
openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'
MAC addresses are always in the format of xx:xx:xx:xx:xx:xx, yours must conform to this format in order to work. For the purpose of this walkthrough the randomly generated address of “d4:33:a3:ed:f2:12 ” will be used.
Changing the MAC Address
If you aren’t in the Terminal yet, open it now. We’ll use the interface en0 for this, but yours could be en1 (read notes at bottom). The command for changing the MAC address is as follows:
sudo ifconfig en0 ether xx:xx:xx:xx:xx:xx
Replace “xx:xx:xx:xx:xx:xx” with the desired MAC address, in the example case this will look like:
sudo ifconfig en0 ether d4:33:a3:ed:f2:12
Hit return and enter the administrators password to set the new address. To confirm it has been changed, type the following:
ifconfig en0 |grep ether
You can also find it in Network preferences, though the GUI doesn’t always report the MAC change immediately, instead waiting until the network connection has been cycled.
Notes & Troubleshooting
If you aren’t sure which interface to use (en0, en1, etc), type “ifconfig” and find it that way. For MacBook Air without an ethernet port the en0 is usually the Wi-Fi interface, whereas a MacBook, iMac, Mac Mini, MacBook Pro, or any Mac that has an ethernet port will probably use en1 for Wi-Fi instead
You may want to note the default hardware MAC address before beginning
Some Macs will use the following command instead:
sudo ifconfig en1 Wi-Fi xx:xx:xx:xx:xx:xx
OS X Lion and later renamed ‘airport’ to Wi-Fi and thus the naming change
You will need access to an admin account or have the root user enabled
This has been tested on a MacBook Air and MacBook Pro running OS X 10.7 and OS X 10.8, older versions of OS X can go here
The whole process should take no more than 15 seconds or so, as demonstrated in this video:
To do this, the first thing you’ll want to do is create a symbolic link from the airport utility to /usr/sbin for easy access. Launch the Terminal and type the following command:
The above command must appear on a single line to work properly. Enter the administrator password to create the symbolic link, which functions as an alias would in the Finder. Now you can use the airport command without the lengthy path to access it.
Now, to scan for and find all wireless networks within range, type the following:
airport -s
The list returned will show all available wifi networks and their router name (SSID), the router address (BSSID), signal strength (RSSI), channel, and security types used by the network.
By watching the output of airport -s and the RSSI strength, you could use the airport command line tool in a similar fashion to the Wi-Fi Diagnostics utility to optimize a wireless connection.
You can also get much of the same detailed information from the Wi-Fi menu by holding the Option key on click, although that will only show you details of one access point at a time.
We recently covered 12 keyboard shortcuts to help navigate around and manipulate text in Mac OS X, and now we’ll show you a handful of similar tricks for use at the command line. These shortcuts can be used just about anywhere in the Terminal, including the bash prompt.
7 Navigation Shortcuts
Navigate around blocks of texts faster with the following shortcuts:
Jump to Beginning of Line – Control+A
Jump to End of Line – Control+E
Go to Next Line – Control+N
Go to Previous Line – Control+P
Delete Previous Word – Control+W
Delete Line from Cursor to Beginning – Control+U
Delete Line from Cursor to End – Control+K
Of course you can also use the arrow keys to navigate within text blocks and to place the cursor for using all commands mentioned.
3 Cutting & Pasting Shortcuts for the Command Line
The command line also has it’s own version of cut and paste, called “kill” and “yank”, and you can reuse two previously mentioned commands for this purpose:
Cut from Cursor to Beginning of Line – Control+U
Cut from Cursor to End of Line – Control+K
Paste Previously Cut Text at Cursor – Control+Y
Because the latter two kill and yank commands do not overwrite the clipboard buffer, they can function as a secondary cut & paste command in many GUI based Mac OS X apps as well.
We recently covered the classic method of adding colors to the command line by editing .bash_profile, but it turns out that Terminal in OS X Lion and OS X Mountain Lion both support custom ANSI colors, giving the ability to easily change the ansi color scheme through external theme files. One such color scheme is the popular TextMate theme IR_Black which has been converted over to Terminal, it’s easy to read subdued pastels aren’t nearly as garish against a dark background and makes for a great looking command line.
Installing IR_Black theme into Terminal is simple:
Uncompress the zip file and double-click on the IR_Black.terminal file to import it into Terminal
Open Terminal Preferences, click on the “Settings” tab, and choose IR_Black as the default
You’ll find the ANSI colors in the same settings window if you want to tweak them a bit or to see a preview of what they’ll look like. If you want the colors to differentiate more, unselect “Use bold fonts” and check the box for “Use bright colors for bold text”, this gives a more clear distinction between items and colors in some commands output.
The other thing you may want to change is window size, found under the “Window” tab, Columns set to “80″ and Rows set to “24″ are the standard width and height settings, rather than the wide and short default of IR_Black.
Adding colorized ls output to the Terminal in Mac OS X is a good way to make navigating around the command line a bit easier on the eyes.
We’ll cover a customizable setting, and you can get a preview of color ls output by typing “ls -G” at the command line. The preview with ls -G will depend on the Terminals color settings and won’t necessarily represent the colors shown below, however.
Open Terminal and type:
nano .bash_profile
Use the arrow keys to navigate to the bottom of the document and paste in either of the blocks of text below, depending on the terminals appearance (see man entry below for further customizations)
Colors for Dark Terminal Themes: export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
Colors for Light Terminal Themes: export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
After the strings are pasted into .bash_profile confirm that it looks something like this in nano:
Hit Control+O to save and open a new Terminal window
Type “ls” or “ls -la” to confirm the colorized output
This will work with Mac OS X 10.6, OS X 10.7, and OS X 10.8, as long as you are using the bash shell. If you aren’t certain what shell you are using, look in the Terminal window titlebar for “bash”, or you can check with the following command:
echo $SHELL
The output will be “/bin/bash” if it’s bash, and something else if not.
For the average user, there isn’t much advantage to use openssl over shasum when verifying checksums, so it’s mostly a matter of habit and whichever is most convenient.