Find file
Fetching contributors…
Cannot retrieve contributors at this time
411 lines (300 sloc) 10.2 KB

MAC OSX terminal commands cheat list

Table of Contents


Use xxd -r -p to convert memory hex bytes into readable text.

For instance, to troubleshoot the content of a REST response buffer stored in a NSConcreteMutableData at address (0x08654860), in XCode debugger window, lldb will return:

(lldb) po 0x08654860
(int) $2 = 140855392 <3c3f786d 6c207665 7273696f 6e3d2231 2e302220 656e636f 64696e67 3d225554 462d3822 20737461 6e64616c 6f6e653d 22796573 223f3e0a 3c657272 6f723e0a 20203c73 74617475 733e3430 313c2f73 74617475 733e0a20 203c7469 6d657374 616d703e 31333438 37373932 38343639 323c2f74 696d6573 74616d70 3e0a2020 3c726571 75657374 2d69643e 5a353054 33593656 39583c2f 72657175 6573742d 69643e0a 20203c65 72726f72 2d636f64 653e303c 2f657272 6f722d63 6f64653e 0a20203c 6d657373 6167653e 5b756e61 7574686f 72697a65 645d2e20 54686520 746f6b65 6e207573 65642069 6e207468 65204f41 75746820 72657175 65737420 6973206e 6f742076 616c6964 2e203937 66616538 34352d34 6537622d 34343537 2d613663 312d3766 36383036 39653639 38363c2f 6d657373 6167653e 0

To convert it, use the command:

echo "3c3f786d 6c207665 7273696f 6e3d2231 (...)" | xxd -r -p

and you get:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  <message>[unauthorized]. The token used in the OAuth request is not valid. 97fae845-4e7b-4457-a6c1-7f68069e6986</message>


Very quickly share a file with someone. In the folder containing the file(s), run

python -m SimpleHTTPServer

you get:

Serving HTTP on port 8000 ...

all files in the folder are now accessible though http://yourIP:8000/


open finder from the terminal at the current folder:

open .

Tired of vi, open a file in default text editor from the terminal:

open -t file.txt

Specify different app:

open -a "Sublime Text 2" file.txt

curl by example


Simple GET



        "name":"BBC 100 - wheelsucker mode",
        "location":"Cartersville, GA",


curl -u username:password http://someURL

Will include basic authentication to the request.

Bypass a self-signed cert warning

curl -k https://mydev-self-signed-dev-server


Post url encoded data (-d or --data flag), in this case login to a Strava REST service:

curl -X POST -d "" -d "password=xxxxxx"

Post raw json data in payload

curl -X POST -H "Content-Type: application/json" -d "{\"prop\":\"value\"}" http://someURL

PUT is nearly identical as POST

curl -X PUT -d "key1=value" -d "key2=value" https://someURL


        "name":"S\u00e9bastien Windal",

Post Form data (useful to upload file) --form or -F flag:

curl --form "fileupload=@filename.txt"


My most commonly used tcpdump command:

sudo tcpdump -X -n -i en1 'tcp port 80'
  • -X - dumps packet payload (both in hex and ASCII), not just header

  • -n - this flag speeds things up, it prevents tcpdump to DNS resolve SRC and DST IP addresses

  • -i en1 - tells to listen to inteface en1, my wifi interface. Run the ifconfig command to see which interface is configured with a valid IP and adjust accordingly.
  • 'tcp port 80' - tells to listen HTTP traffic. The syntax is the pcap filter syntax described in man pcap-filter. Other common filters:
    • net ipaddress - only show traffic between you and ip address.
    • dst net ipaddress - to only see your request to
    • src net ipaddress - to only see response

other options:

  • -A - dumps packet in ASCII only
  • -s 1500 - only captures 1500 bytes per packet instead of 65536 (1500 is the max ethernet MTU).
  • -x - same as -X but only dumps hex
  • -l - Make stdout line buffered. use it if you are going to massage and filter output using grep or sed.

Note you can also listen to local traffic by listening on lo0 (on MAC OSX)

sudo tcpdump -X -n -i lo0 'tcp port 80'


Command line image resizing tool.

typical usage, resize an image:

sips --resampleWidth newWidth myimage@2x.png --out myimage.png

get the width of an image:

sips -g pixelWidth myimage.png

automatic resizing of all images in current folder:

# Downsamples all retina ...@2x.png images.

echo "Downsampling retina images..."

find "$dir" -name "*@2x.png" | while read image; do

    outfile=$(dirname "$image")/$(basename "$image" @2x.png).png

    if [ "$image" -nt "$outfile" ]; then
        basename "$outfile"

        width=$(sips -g "pixelWidth" "$image" | awk 'FNR>1 {print $2}')
        height=$(sips -g "pixelHeight" "$image" | awk 'FNR>1 {print $2}')
        sips -z $(($height / 2)) $(($width / 2)) "$image" --out "$outfile"

        test "$outfile" -nt "$image" || exit 1

magic !number command

history | grep sips
  391  sips
  394  sips -s format png --resampleWidth  480 GoogleSpreadSheet.fullsize.png --out GoogleSpreadSheet.png
  395  sips -s format png --resampleWidth 960 GoogleSpreadSheet.fullsize.png --out GoogleSpreadSheet@2x.png
  402  sips -s format png --resampleWidth 960 GoogleSpreadSheetColors.fullsize.png --out GoogleSpreadSheetColors@2x.png
  405  sips -s format png --resampleWidth 480 GoogleSpreadSheetColors.fullsize.png --out GoogleSpreadSheetColors@.png
  409  sips -s format png --resampleWidth 480 GoogleSpreadSheetColors.fullsize.png --out GoogleSpreadSheetColors.png
  410  sips -s format png --resampleWidth 960 GoogleSpreadSheetColors.fullsize.png --out GoogleSpreadSheetColors@2x.png
  429  sips -s format png --resampleWidth 320 ScreenShot1\@2x.png --out ScreenShot1.png
  430  sips -s format png --resampleWidth 320 ScreenShot2\@2x.png --out ScreenShot2.png
  431  sips -s format png --resampleWidth 320 ScreenShot3\@2x.png --out ScreenShot3.png
  546  history | grep sips



will run that command again.

Bonjour Service Discovery

Browse available services

dns-sd -B type domain

will discover a certain number of "standard" services on the local domain (not clear what defaults it peaks).

dns-sd -B . local

To check for a paricular service

dns-sb -B _WGen local


Browsing for _WGen._tcp.local
DATE: ---Mon 03 Dec 2012---
14:15:03.095  ...STARTING...
Timestamp     A/R Flags if Domain                    Service Type              Instance Name
14:15:03.096  Add     2  4 local.                    _WGen._tcp.               MATH2SESSION

Retrieve connection info about a discovered service:

dns-sd -L name type domain

The name parameter should be the last column of the output of the dns-sd -B command.

for instance

dns-sd -L MATH2SESSION _WGen local


Lookup MATH2SESSION._WGen._tcp.local
DATE: ---Mon 03 Dec 2012---
14:20:30.902  ...STARTING...
14:20:30.903  MATH2SESSION._WGen._tcp.local. can be reached at Sebastien-WGEN-iPad.local.:51290 (interface 4)

Retrieve connection record

dns-sd -q name

This time name is the FQDN (fully qualified domain name) displayed in response to the dns-sd -L command. For instance:

dns-sd -q Sebastien-WGEN-iPad.local


DATE: ---Mon 03 Dec 2012---
14:24:09.184  ...STARTING...
Timestamp     A/R Flags if Name                             T   C Rdata
14:24:09.185  Add     2  4 Sebastien-WGEN-iPad.local.       1   1

more details: man dns-sd

nc (netcat)

The nc (or netcat) utility is used for just about anything under the sun involving TCP or UDP. It can open TCP connections, send UDP packets, listen on arbitrary TCP and UDP ports, do port scanning, and deal with both IPv4 and IPv6.

send udp bytes over the network

echo "hello world" | nc -u localhost 1025


Node Package manager.

The syntax to add a dependency the right way:

npm install restify --save

Will also add the restify dependency in the package.json file...

Create a self signed SSL cert.

Follows instructions found, which consist of:

Create a key file

openssl genrsa -out key.pem 1024

Create a certificate request for the key

openssl req -new -key key.pem -out request.pem

Create a self signed cert (for development purposes)

openssl x509 -req -days 30 -in request.pem -signkey key.pem -out certificate.pem