Mac Commanline Tool For Unarchiving

For most casual users, the OS X command line, accessed via the Terminal app, is at least as murky and daunting as the Windows Command Prompt, to be used only in times of extreme distress. For those users, this is usually when something has gone inexplicably wrong, and typing cryptic commands into the prompt seems the only hope for a cure. Of course, most likely they’re actually restarting a launchd service or deleting a plist file.

To those familiar with the Unix shell, the command line or terminal is a powerful tool to be used to facilitate many system functions and interactions. Because OS X is built around a BSD core, you can bring over your fancy one-liners and skip the cumbersome GUI tools to do simple things like walking a directory tree, deleting every file older than 30 days, or pulling a list of files in the current directory that contain a specific text string. Although graphical interfaces can simplify many tasks, they can also complicate other tasks -- and the command line comes to the rescue.

  • In AppleScript, the do shell script command is used to execute command-line tools. This command is implemented by the Standard Additions scripting addition included with OS X. The direct parameter of the do shell script command is a string containing the shell code you want to execute, as.
  • Install command line RAR and UnRAR tools on Mac OS X (updated for Yosemite 10.10.x) Feb 1, 2013| Applications, Unix & Terminal| 8 comments Here is how to install a free command line UnRAR tool (a RAR file extractor) and the RAR tool on Mac OS X.

Note: Mac OS X and Linux users have robust command line interfaces baked right into their systems. To get to them, head to Applications->Utilities->Terminal in Finder. It varies in Linux.

OS X has hidden gems that even power users might not know about. Here’s a list of 10 handy utilities that allow you to perform many functions on your Mac from the command line. You should find all of them useful and, in at least one case, even entertaining.

1. pbcopy and pbpaste: Copy and paste to/from the clipboard

The pbcopy and pbtaste utilities work in concert, allowing access to and from the system clipboards/pasteboards from the command line. For instance, if you wanted to list all of the files in a directory that start with the letter 'f' and put that list into the clipboard, you’d type the following:

Commanline

$ ls f* | pbcopy

Boom -- that output can then be pasted into any GUI app.

The converse works as you might expect. If you have that list of files in the clipboard from another app, you can process it on the command line with pbpaste:

$ pbpaste | grep foo

It will use the grep command to extract only the lines containing the string foo.

If your work takes you into the command line in concert with GUI apps, these two commands can definitely come in handy.

2. rsync: synchronize files or directories

The rsync utility can synchronize directory trees between folders on the same system or between folders on a local and a remote system. It’s immensely useful and has been a bastion of IT for many years. It’s also included in OS X.

If you have a need to keep two directory trees identical, using rsync on the local system is trivial:

$ rsync -av /path/to/directory1/ /path/to/directory/2/

This will make sure that any and all files in /path/to/directory1/ also exist in /path/to/directory2/. If you want to make the directories exactly identical, you’ll need to instruct rsync to also delete files in /path/to/directory2/ that do not exist in /path/to/directory1/:

$ rsync -av --delete /path/to/directory1/ /path/to/directory2/

If you don’t want the files listed during synchronization, remove the v flag:

$ rsync -a --delete /path/to/directory1/ /path/to/directory2/

Or if you want to see which files would be copied or deleted, add an n:

$ rsync -avn --delete /path/to/directory1/ /path/to/directory2/

You can also use rsync between different systems, as long as the remote system has rsync installed and is running SSH:

$ rsync -av --delete /path/to/directory1/ user@remotesystem:/path/to/directory1/

Note that the trailing slash is important here. It indicates that rsync is to read files within the source directory and synchronize them within the destination directory. Omit the trailing slash, and rsync will copy (append) the source directory to the destination directory, creating an additional directory level that you might not have intended.

To enable SSH access on a Mac, open System Preferences, go to Sharing, and select Remote Login. You will then be able to rsync to the Mac over SSH, or use SSH to connect to a shell on the system.

3. ditto: Copy or merge directories or archives

The ditto command is superficially similar to rsync, but in reality it’s a very different tool. It’s been included in OS X for quite some time, but remains relatively unknown.

Like rsync, ditto can be used to copy directory trees, preserving permissions, ownership, and metadata. Thus:

$ ditto /path/to/source /path/to/destination

Mac command line tool

If the destination directory doesn’t exist, ditto will make an exact copy of the source directory there. If the destination directory does exist, ditto will merge the source directory with the destination, overwriting duplicate filenames. For instance, you could use ditto to merge the contents of two large directories of pictures into a single nested directory structure.

But ditto goes further, as it can also create, extract, and manipulate CPIO (Copy In, Copy Out) and Zip archives. You can specify a bill of materials (bom) document that ditto will use to selectively copy or merge, have ditto omit metadata during the file copies, or even instruct ditto to reduce universal binaries to one specific architecture during an operation.

The ditto utility is a fairly complex tool that can be very handy when used properly, but it can also take some experimentation to fully understand.

4. tmutil: Back up and restore with Time Machine

Apple’s Time Machine feature is extremely useful in providing a way for users to maintain ongoing backups of their computers to an external drive such as a NAS or USB drive. That said, the “Star Wars” interface can be cumbersome when power users are trying to navigate backups, and the controls in System Preferences are quite Spartan.

Luckily, tmutil is there to fill in the gaps when you need it.

For instance, whereas the Time Machine GUI will show you the latest backup, if you want to show all available backups, run the following:

$ tmutil listbackups

You’ll see a list of every accessible backup of the current system. To view the latest backup, simply enter the following:

$ tmutil latestbackup

You can also use tmutil to start and stop backups, compare backups to one another, analyze the amount of change between backups, inherit backups that might have been made from an older system, show information about backup destinations, associate and disassociate backup destinations, and even restore files from a backup.

Basically, all of the backup-related tasks that a power user is missing in the GUI is in tmutil. If you are in dire straits and need to dig deeper into backups to fix something, it can be a lifesaver.

5. fs_usage: Display file system activity

If you’ve ever been in a position where your disk is thrashing and you want a quick command-line look at which system processes are causing the turmoil, fs_usage has your back. This tool provides a constant stream of real-time information on which processes are accessing the file system.

By default, fs_usage exempts a few processes from the output, including Terminal and Secure Shell (sshd). You can run fs_usage in Terminal like so:

$ sudo fs_usage

If you’re using another terminal application, you’ll need to exempt it from the output with the -e switch:

$ sudo fs_usage -e iTerm

The above will exempt both fs_usage and the iTerm app from the output.

In addition to providing a systemwide view, fs_usage can profile individual processes, such as Google Chrome:

$ sudo fs_usage 'Google Chrome'

6. drutil and hdiutil: Burn CDs and DVDs and manipulate disk images

If you’ve ever wanted to burn a data DVD or audio CD quickly and easily, drutil is for you. With it, you can burn a directory tree to a CD with a single line:

$ drutil burn /path/to/folder

If you want to burn an audio CD, simply reference a directory full of audio files:

$ drutil burn -audio /path/to/folder

This utility can also come in handy for erasing CD-RW media with the erase command (drutil erase /path/to/folder). With the bulkerase command, it will erase a CD-RW disc, eject it, and wait for another to be inserted, then rinse and repeat.

The hdiutil utility is somewhat related, in that hdiutil is used to manipulate disk images. You can use hdiutil to create an Apple disk image (that is, a DMG file) from a directory path:

$ hdiutil create -srcfolder /path/to/files/ myfiles.dmg

In El Capitan, you can burn ISO images to CDs with the following command:

$ hdiutil burn /path/to/file.iso

The hdiutil utility has many other functions as well, such as mounting and unmounting images, converting image formats, creating encrypted images, and verifying images.

7. system_profiler: Report system information

When debugging problems or investigating a system, it’s handy to be able to get a report on all of the pertinent information about the hardware and software in use. That’s what system_profiler does, and it outputs that report to a text file for easy reading.

For most purposes, the basic report is sufficient:

$ system_profiler -detailLevel basic > report.txt

This will give you tons of data on the system, from basics like CPU, RAM, graphics, and storage to serial number, hardware UUID, network information, RAM slot population, network particulars, power info, printer software, USB, Thunderbolt, and Time Machine backup information.

It’s a one-stop shop for all the data you might need on a particular Mac. This is especially handy when trying to troubleshoot problems with a remote system you can’t access, such as when Mom or Dad call with an inexplicable problem.

8. tar, gzip, bzip2, and zip: Create and open compressed archives

In the Unix world, tar (short for “tape archive”) was originally used to copy files to backup tapes in a standardized format.

Today, we no longer use tar in quite the same way. We use it to create archives of individual files or directories. Employed alongside compression tools gzip and bzip2, tar lets us create compressed archives of files. The result is similar to a Zip file archive, which is used on Mac, Windows, and other platforms.

To create a gzipped tar archive of a directory, we might run:

$ tar zcpf myfiles.tgz /path/to/files

This will create myfile.tgz, which is a gzipped tar archive of all of the files in the referenced path. If we want to use bzip2, we might get a smaller archive, but it might take longer to compress and decompress:

$ tar jcpf myfiles.tbz /path/to/files

And we can always use regular Zip:

$ zip –r myfiles.zip /path/to/files

To open a gzipped tar file, we run this command:

$ tar zxf myfiles.tgz

To open a bzipped (bzip2) archive, the command is the following:

$ tar jxf myfiles.tbz

And for Zip archives, the command is unzip:

$ unzip myfiles.zip

You might get better mileage out of tar and gzip or bzip2 than zip for some file types, but be warned that Windows users won’t be able to open the archives without specific software, whereas Zip files will open automatically on modern Windows versions.

9. mdfind: Perform powerful Spotlight searches

OS X has had Spotlight search for years. Spotlight indexes files on your disk and allows for advanced searching by metadata, file type, file contents, and more. Fortunately, Spotlight searches are also available on the command line via mdfind.

This works exactly like the Spotlight tool in the Finder, but it’s more flexible in search types, and it returns all of the data found. For instance, the following command will return literally everything indexed by Spotlight containing the keyword foobar:

$ mdfind 'foobar'

You can search all metadata too, such as file type:

$ mdfind 'kMDItemContentType 'com.microsoft.word.doc'

You can search by file type with keywords:

$ mdfind 'kind:pdf Bread cheese salami'

You can even search based on time frame:

$ mdfind -onlyin ./tmp/ 'kMDItemFSContentChangeDate >= $time.today(-2)'

The Spotlight search GUI is certainly handy for simple searches, but if you’re really trying to scour your storage for files, mdfind might be a better bet.

10. say: Have your Mac read a file to you

The say command can be useful for those who need audio assistance due to disability, but it can also be a lot of fun. This tool does what you might expect: It translates text to speech. At its most basic, it’s very simple to use:

$ say 'Hello world'

You’ll get a stereotypical robot voice saying “Hello world.” However, it doesn’t stop there. There are 64 different voices to choose from, in a variety of languages. In some of the foreign voices, English text will be uttered in an approximation of a speaker of that language’s English accent. You can see a list of all of the voices with this command:

$ say -v ‘?’

Once you’ve decided on a suitable voice, you can have say, well, say anything on the command line or in a normal text file. Include the --interactive flag, and say will highlight the words as they are read aloud:

$ say -v Vicki -f myfile.txt --interactive

You can even set the rate at which text is read back, and if the destination system is properly configured, you can have say read back text on a remote system.

The Mac’s GUI makes most things easy, and it’s a pleasant place to spend your time. But there’s more to the Mac than the pretty face. When the GUI seems too limited or too slow, you might find it easier to pop open the Terminal and tap the power of the command line. In addition to these 10 essentials, check out the 20 OS X command-line secrets in InfoWorld’s previous article.

aexml

Syntax

Description

Translates SOAP and XML-RPC requests into Apple Events understood by Mac OS X applications. The target application can be specified by name, process ID, process serial number, or signature. If no target is specified, a sandbox application is launched to handle the request. Output, if any, is in the form of XML or a one-line error.

Options/Usage

-soap
Forwards a SOAP request to the target application.
-SOAPAction
Provides the SOAPAction header. If specified as -, the header is read from input.
-xmlrpc
Forwards an XML-RPC request to the target application.
-in
Specifies source of input. Defaults to - (standard input).
-out
Specifies location of output. Defaults to - (standard output).
-name
Specifies target application by pathname.
-pid
Specifies target application by Unix PID.
-psn
Specifies target application by Carbon Process Manager process serial number.
-sig
Specifies target application by signature. This is a four-character code unique to an application.The signature is usually the same as the application's creator code. In an application bundle, it is specified by the CFBundleSignature property in Info.plist.

Location

/usr/bin

Operating System

Mac OS X

configd

Syntax

Description

This is the System Configuration Server. configd is normally started as a daemon during the boot process. It monitors changes to network-related items, such as link status, DHCP assignments, PPP connections, and IP configuration, and provides an API for applications to be notified of these changes. To monitor various items, it uses a set of plug-in configuration agents, including the Preferences Monitor, the Kernel Event Monitor, the PPP Controller Agent, the IP Configuration Agent, and the IP Monitor Agent. The agent plug-ins are located in /System/Library/SystemConfiguration.

More information on the System Configuration framework can be found at http://developer.apple.com/techpubs/macosx/Networking/SysConfigOverview926/.

Options/Usage

-b
Disables loading of all agents.
-B
Disables loading of the specified agent.
-d
Disables daemonization; runs process in foreground.
-t
Loads the agent specified by pathname.
-v
Enables verbose logging.
-V
Enables verbose logging for the specified agent.

Location

/usr/sbin

Operating System

Darwin

DirectoryService

Syntax

Description

This is the server process for the Directory Services framework.

Options/Usage

-h
Prints a usage statement for the first form of command invocation to standard output.
-v
Prints software release version to standard output.
-appledebug
Runs service in debug mode.
-appleframework
Starts service normally. This is the default.
-applenodaemon
Disables daemonization; runs service in foreground.
-appleoptions
Prints a usage statement for the second form of command invocation to standard output.
-appleperformance
Runs service in foreground and logs extensively.
-appleversion
Prints software build version to standard output.

Location

/usr/sbin

Operating System

Darwin

disktool

Syntax

Description

Controls disks, including mounting, unmounting, ejecting, enabling permissions, and volume naming. Most options require a device name argument (for example, disk0), and some options require additional parameters.

Options/Usage

-a
Adds disk to Disk Arbitration tables, to notify applications of a mounted volume. This is useful if you have forced a mount, thus bypassing standard notification.
-d
Removes disk from Disk Arbitration tables, to notify applications of a dismount. This is useful if you have forced a dismount, thus bypassing standard notification.
-e
Ejects disk. Takes an additional argument that is normally set to 0.
-g
Gets HFS encoding on a volume.
-m
Mounts disk.
-n
Names volume.
-o
Opens vacant drive doors.
-p
Unmounts partition. Device name is that of a partition (for example, disk0s5). Takes an additional argument that is normally set to 0.
-r
Refreshes Disk Arbitration.
-s
Sets HFS encoding on a volume. Takes encoding as additional integer argument.
-u
Unmounts disk. Takes an additional argument that is normally set to 0.
-va
Adds device to /var/db/volinfo.database.
-vd
Deletes device from /var/db/volinfo.database.
-vs
Displays status of device in /var/db/volinfo.database.
-x
Disallows dismounts and ejects.
-y
Allows dismounts and ejects.

Location

/usr/sbin

Operating System

Darwin

dynamic_pager

Syntax

Description

Manages virtual memory swap files. This tool is started from /etc/rc during the boot process.

Options/Usage

-F
Specifies the base absolute pathname for swap files. Swap filenames consist of this base and a whole number suffix, starting at 0. The default is /private/var/vm/swapfile.
-H
Creates an additional swap file when free swap space drops below the hire_point in bytes. The default is 0, which disables the use of this swap space.
-L
Attempts to consolidate memory and remove a swap file when free swap space rises above the layoff_point in bytes. The layoff_point must be set higher than the sum of the swap file size and the hire_point, unless it is set to 0 (the default), which disables layoffs.
-P
Determines the priority of this swap space. The default is 0.
-S
Determines the size of swap files created, in bytes. The default is 20000000.

Location

/sbin

Operating System

Darwin

ipconfig

Syntax

Description

Interacts with the IP Configuration Agent of configd to manage network configuration changes.

Options/Usage

getifaddr
Prints the specified network interface's IP address to standard output.
getoption
Prints the value of the specified DHCP option to standard output. If interface is specified, the option is interface-specific. If empty quotes are used instead, the option is global. Option names and numeric codes are DHCP-standard (such as host_name, domain_name, netinfo_server_address, etc.).
getpacket
Prints DHCP transaction packets to standard output.
ifcount
Prints the number of network interfaces to standard output.
set
Sets the method by which the specified network interface is assigned an IP address. Using BOOTP or DHCP causes the system to attempt to contact a server of the appropriate type to obtain IP configuration information. Using INFORM sets the IP address locally, but initiates a DHCP request to obtain additional IP configuration information (DNS servers, default gateway, etc.). Using MANUAL indicates that all IP configuration information is set locally.
waitall
Sets the configurations of all network interfaces according to the specifications in /etc/iftab.

Location

/usr/sbin

Operating System

Darwin

opendiff

Syntax

Description

Opens the two designated files in the FileMerge application.

Unarchiving

Options/Usage

-ancestor
Compares the two files against a common ancestor file.
-merge
Merges the two files into a new file.

Location

/usr/bin

Operating System

Mac OS X

pbcopy

Syntax

Description

Copies standard input to the pasteboard buffer. The pasteboard is used to implement GUI copy, cut, and paste operations, drag-and-drop operations, and the Cocoa Services menu.

Options/Usage

-help
Prints an unhelpful usage statement to standard output.

Location

/usr/bin

Operating System

Mac OS X

pbpaste

Syntax

Description

Prints the contents of the pasteboard to standard output. The combination of pbcopy and pbpaste may be an interesting tool to use in scripting. However, the system's global pasteboard can be modified by other processes at any time, which limits the tool's actual usefulness.

Options/Usage

-help
Prints a usage statement to standard output.
-Prefer
Specifies the output format to use if the desired format (ASCII, Rich Text Format, or PostScript) is available in the pasteboard.

Location

/usr/bin

Operating System

Mac OS X

pl

Syntax

Description

Translates XML property list files into a more compact 'key = value' format. Also translates between this and a serialized binary format, in either direction. XML is read from standard input, 'key = value' data is read from standard input and written to standard output, and serialized binary data is read from and written to files specified with arguments.

Options/Usage

-input
Specifies a serialized binary file as input.
-output
Specifies a serialized binary file as output.

Examples

cat foo.plist | pl
Translates XML property list to 'key = value' format.
cat foo.plist | pl | pl -output foo.bin
Translates XML property list to serialized binary format.
pl -input foo.bin
Translates serialized binary file to 'key = value' format.

Location

/usr/bin

Operating System

Mac OS X

scselect

Syntax

Description

Changes active network location, similar to selecting a network Location from the Apple menu. If there are no arguments, a usage statement and a list of defined Locations (or 'sets') as defined in the Network System Preferences panel is printed to standard output, along with an indication of which location is currently active. Locations can be referred to by name or by integer ID.

Options/Usage

-n
Changes the active network Location, but does not apply the change.

Location

/usr/sbin

Operating System

Darwin

Mac Command Line List

scutil

Syntax

Description

Provides control of the System Configuration framework's dynamic store. scutil opens an interactive session with configd, in which various commands are available to view and modify System Configuration keys.

As a quick sample run-through, invoke scutil. You will be placed at the scutil prompt. Enter open to start the session with configd, then enter list. You will see a set of keys, some of which are provided by the System Configuration framework (such as the keys in the File: domain), some of which are obtained from the preferences file /var/db/SystemConfiguration.xml (the Setup: keys), and some of which are published by the configuration agents (the State: keys). Enter get State:/Network/Global/DNS to load the dictionary associated with that key. Then run d.show to display it. You should see a list of DNS servers and search domains configured on your system. Finally, run close, then quit.

Options/Usage

-r
Checks for reachability of the node or address. (Any numerical argument seems to result in Reachable status.)
-t
Specifies the timeout to wait for the presence of a data store key, in seconds. The default is 15.
-w
Exits when the specified key exists in the data store or when the timeout has expired.

Commands

scutil enters interactive mode when it is invoked with no arguments.

add key [temporary]
Adds a key to the data store with the value of the current dictionary. The temporary keyword causes it to be flushed when the session to configd is closed.
close
Closes a session with configd.
d.add key [* | ? | #] value...
Adds an entry to the current dictionary. The optional type specifier can designate the values as arrays (*), booleans (?), or numbers (#).
d.init
Creates an empty dictionary.
d.remove key
Removes the specified key from the current dictionary.
d.show
Displays the contents of the current dictionary.
f.read file
Reads prepared commands from a file.
get key
Causes the value of the specified key to become the current dictionary.
help
Prints a list of available commands.
list [key_pattern]
Lists keys in the System Configuration data store. The key_pattern can restrict which keys are output, but key_pattern appears to be quite limited.
n.add { key | key_pattern }
Requests notification of changes to the specified keys.
n.cancel
Cancels n.watch settings.
n.changes
Lists changed keys that have been marked with notification requests.
n.list [key_pattern]
Lists keys upon which notification requests have been set.
n.remove { key | key_pattern }
Removes notification requests for the specified keys.
n.watch [verbose]
Causes changes to keys marked with notification requests to issue immediate notices, obviating the need to use n.changes to serve notice that the change has occurred.
notify key
Sends a notification for the specified key.
open
Opens a session with configd.
quit
Exits the scutil session.
remove key
Removes the specified key from the data store.
set key
Sets the specified key to the value of the current dictionary.

Location

/usr/sbin

Operating System

Darwin

SplitForks

Syntax

Description

Splits the resource fork out of a dual-forked file into a file named ._pathname. You can also do this with cp pathname/..namedfork/rsrc ._pathname. This method results in a resource file amenable to processing by DeRez, whereas the output of SplitForks does not appear to produce a file that DeRez can understand.

Options/Usage

-u
Prints a usage statement to standard output.
-v
Enables verbose output.

Location

/Developer/Tools

Operating System

Mac OS X

tiff2icns

Syntax

Description

Converts TIFF image files to Apple icon (ICNS) files. If output_filename is not specified, the output file receives the same name as the input file, with the filename extension changed to .icns.

Options/Usage

-noLarge
Prevents the creation of the highest resolution icons.

Location

/usr/bin

Mac Command Line Interface

Operating System

Mac OS X

tiffutil

Syntax

Description

Manipulates TIFF image files.

Options/Usage

-cat
Concatenates multiple input files.
-dump
Prints a list of all tags in the input file to standard output.
-extract
Extracts an individual image from the input file, with 0 designating the first image in the file.
-f
Specifies the compression factor to use with JPEG compression. The value can range from 1 to 255. The default is 10.
-info
Prints information about images in the input file to standard output.
-jpeg
Specifies the use of JPEG compression when producing the output file.
-lzw
Specifies the use of Lempel-Ziv-Welch compression when producing the output file.
-none
Specifies the use of no compression when producing the output file.
-output
Specifies the name of the output file; defaults to out.tiff.
-packbits
Specifies the use of PackBits compression when producing the output file.
-verboseinfo
Prints lots of information about images in the input file to standard output.

Location

/usr/bin

Operating System

Mac OS X

udf.util

Syntax

Description

Mounts UDF (DVD) filesystems into the directory hierarchy.

Options/Usage

-m
Mounts the device.
-p
Probes the device for mounting.
-u
Unmounts the device.
device
Specifies the DVD device filename, for example, disk1.
mount_point
Specifies the directory on which the DVD filesystem will be mounted.

Location

Mac Command Line Tool For Unarchiving Gmail

/System/Library/Filesystems/udf.fs

Operating System

Darwin

vsdbutil

Syntax

Description

Install Command Line Tools Mac

Enables or disables the use of permissions on a disk volume. This is equivalent to using the Ignore Privileges checkbox in the Finder's Info window for a mounted volume. The status of permissions usage on mounted volumes is stored in the permissions database, /var/db/volinfo.database.

Options/Usage

Command Line For Mac Address

-a
Activates permissions on the volume designated by pathname.
-c
Checks the status of permissions usage on the volume designated by pathname.
-d
Deactivates permissions on the volume designated by pathname.
-i
Initializes the permissions database to include all mounted HFS and HFS+ volumes.

Location

Mac Command Line Tool For Unarchiving A Order

Operating System

Darwin

Copyright © 2003 O'Reilly & Associates. All rights reserved.

Mac Command Line Tool