Welcome!

Think Labs is an ongoing effort by Seven2 to provide research and educational opportunities in the web development and mobile field. To see what we’ve been cookin’ up, check out our blog postings.

Created by
Seven2 Login

Categories
Tags
Team Think Labs | Get Under the Hood with Terminal
1742
single,single-post,postid-1742,single-format-standard,ajax_fade,page_not_loaded,,,wpb-js-composer js-comp-ver-4.2.3,vc_responsive

Get Under the Hood with Terminal

Here is a collection of command-line tricks for boring, repetitive, and sometimes difficult tasks.

File tricks

show/hide hidden files

defaults write com.apple.finder AppleShowAllFiles true/false
killall Finder

 

Change a file’s modification date to now:

touch file

 

prevent .DSstore files

defaults write com.apple.desktopservices DSDontWriteNetworkStores true
killall Finder

Image manipulation

Rotate image 45 degrees clockwise

sips --rotate 45 image.jpg

 

Flip image horizontally or vertically

sips --flip horizontal|vertical image.jpg

 

Crop image to a height of 100px and a width of 150px. fit specified size.

sips --cropToHeightWidth 100 150 image.jpg

 

Pad image to a height of 100px and a width of 150px, use red as the padding color (default is black).

sips --padToHeightWidth 100 150 --padColor FF0000 image.jpg

 

Resample image to a height of 100px and a width of 150px. Image apsect ratio may be altered.

sips --resampleHeightWidth 100 150 image.jpg

 

Resample image to width of 300px.

sips --resampleWidth 300 image.jpg

 

Resample image to height of 200px.

sips --resampleHeight 200 image.jpg

 

Resample image so height isn’t greater than 100px and width isn’t greater than 150px.

sips --resampleHeightWidthMax 100x150 image.jpg

Text Trickery

Count number of words in the text in the Clipboard:

pbpaste | wc -w

 

Sort lines of text in the Clipboard and copy them back to the Clipboard:

pbpaste | sort | pbcopy

 

Strip duplicate lines from lines of text in the Clipboard and copy only one instance of each duplicate line back to the Clipboard (output is sorted):

pbpaste | sort | uniq | pbcopy

 

Find duplicate lines from lines of text in the Clipboard and copy only one instance of each duplicate line (stripping non-duplicates) back to the Clipboard (output is sorted):

pbpaste | sort | uniq -d | pbcopy

 

Strip duplicate lines from lines of text in the Clipboard and copy only one instance of each line (stripping duplicates entirely) back to the Clipboard (output is sorted):

pbpaste | sort | uniq -u | pbcopy

 

Tidy up HTML in the Clipboard and copy it back to the Clipboard:

pbpaste | tidy | pbcopy

 

Convert tabs to spaces for the lines in the Clipboard:

pbpaste | expand | pbcopy

 

Convert spaces to tabs for the lines in the Clipboard:

pbpaste | unexpand | pbcopy