Terminal Commands – Part 3

This post follows up on the previous 2 posts. Here we will look at some advanced commands. Note that this is by no means a comprehensive list. You can visit the online version of the man pages: Apple Man Pages

Here are the links for the previous posts.

Terminal Commands – Part 1

Terminal Commands – Part 2

The commands are explained with some common tasks in mind. Some of the steps are there to illustrate the usage of the commands. To find out other tasks that can be performed using these commands simply refer to the man pages.

FILE SYSTEM

diskutil

The diskutil command is a handy tool to run disk utility via the terminal. A full list of tasks that can be executed are available via the man command.

Example:

There could be situations where you have encrypted your USB drive & have forgotten the password for the same. While there is no way to retrieve the data, it is still possible for you to use the USB disk. Let’s use the diskutil command to do this.

– Launch terminal

– Make sure that the USB is properly connected

– Run the command diskutil cs list

– This lists all the core-storages that are connected to your system.

– Next to the Logical Volume Group select the alphanumeric id & copy it (make sure you select the correct logical volume group).

– Type the command diskutil cs delete <id>

– Replace the id with the alphanumerics id you copied earlier.

– This will completely remove the encrypted partition. As mentioned earlier you will loose all the data that is already there on the partition.

diskutil man page

fsck

File System Check command. This command is used to check different Filesystems by invoking the corresponding sub command.

fsck man page

hdiutil

hdiutil is used to perform some other tasks related to storage devices. A good example of this is the creation of different kinds of disk images.

Example:
Let us create a disk image for the ~/Documents directory

– Launch the terminal application

cd ~/

mkdir ImageDemo

hdiutil create -srcfolder ImageDemo ImageDemo.dmg

Apart from the above example, there are a lot of other tasks that can be performed using hdiutil. For full information run the man command.

hdiutil man page

mount

The mount command is used to mount a volume via the terminal. A volume can be mounted as a Read-Write or a read only. For full details on the functionality run the man mount command

Syntax: mount <options> <volume location>

mount man page

GETTING INFORMATION RELATED TO THE SYSTEM & FILES

uptime

Shows how long the system has been running.

uptime man page

ioreg

Get information out of the io registry.

Example:
Suppose we want to get information about the serial number. We would use the ioreg command.

– launch terminal

cd ~/Documents

ioreg -l | grep “IOPlatformSerialNumber”

Optionally you can pipe the information to a file & read it later.

ioreg man page

system_profiler

Used to get system related information. it can generate a small or a detailed report depending on what option is used. For full information access the man pages for the command.

system_profiler man page

top

Displays information about the various processes running within the system including the usage 7 state. To get more information about the full functionality visit the man pages.

top man page

METADATA

mdls

Used to get the metadata for a given file or folder. The data is displayed on the screen.

mdls man page

mdutil

Manages spotlight search indexes.

mdutil man page

NETWORKING

networksetup

This command is used to access the information that is found within the System Preferences > Network Preferences pane.

You can use this command to do some quick command line configuration of the network settings.

A good example is to manually configure the settings while booted in the OS X Recovery partition. Here is an Apple Support Document which talks about the same.

http://support.apple.com/kb/HT5034?viewlocale=en_US

networksetup man page

MISCELLANEOUS

tar

Used to compress file(s) into a single tar file or decompress.

Example:

This example demonstrates how to use the tar command.

– Launch terminal

cd ~/Documents

mkdir Docs

cd Docs

echo “A” | cat > file1

echo “A” | cat > file2

echo “A” | cat > file3

echo “A” | cat > file4

Now to compress all the files

tar -cvf compressedFiles.tar file*

To uncompress them all

tar -xvf compressedFiles.tar

tar man page

tmutil

Manage Time machine from the terminal. Useful command to manage time machine from the command line.

tmutil man page

fdesetup

Used to mange file-vault from the command line

fdesetup man page

Advertisements

4 thoughts on “Terminal Commands – Part 3

  1. Pingback: Configuring an SVN Server on OS X on your Local Network | Arun Patwardhan's Blog

  2. Pingback: Configuring/Troubleshooting OS X Using Command Line | Arun Patwardhan's Blog

  3. Pingback: Automation on the Mac | Arun Patwardhan's Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s