Skip to content

Instantly share code, notes, and snippets.

@briannhinton
Last active April 19, 2021 00:59
Show Gist options
  • Save briannhinton/e7a7b9c52c511479cf671864942634db to your computer and use it in GitHub Desktop.
Save briannhinton/e7a7b9c52c511479cf671864942634db to your computer and use it in GitHub Desktop.
Useful terminal commands for Mac.

Terminal Commands

In the words of the great Willie Wonka:

A little nonsense now and then is relished by the wisest men.

A collection of useful terminal commands:

// remove all node_modules from a folder
for package in `ls node_modules`; do npm uninstall $package; done;

// Keep mac awake until app is idle
caffeinate -i open -W -a iMovie.app

// Show hidden files (FALSE to hide)
defaults write com.apple.finder AppleShowAllFiles TRUE

// Create textfile of directory and all sub-directories (use .csv to maked a CSV)
ls -R /DIRECTORY > file-name.txt

// Find the PID running on port 3000
lsof -wni tcp:3000
//kill that process
kill -9 PID

// Compress Image using Imagemagick
convert -strip -interlace Plane -quality 85% source.jpg result.jpg

// Compress all subdirectories into their own .zip
for i in */; do zip -r "${i%/}.zip" "$i"; done

// Restart Wireless Networking (use en0 for Ethernet)
As Sudo:
ifconfig en1 down
ifconfig en1 up

// Convert ISO to DMG
hdiutil convert /path/imagefile.iso -format UDRW -o /path/convertedimage.dmg

// Restart OS X UI
sudo killall -HUP WindowServer

// Generate a gif from a mov with ffmpeg
ffmpeg -i video.mov -pix_fmt rgb24 output.gif

// Reduce the frame rate and size. Set the start time and duration
ffmpeg -ss 00:00:00.000 -i video.mov -pix_fmt rgb24 -r 10 -s 320x240 -t 00:00:10.000 output.gif

// Optimize gif with ImageMagick
convert -layers Optimize output.gif output_optimized.gif

// Optimize gif with gifsicle
gifsicle -O3 output.gif -o ouptput-optimized.gif
# Moving the cursor – fast
CTRL+a         Go to the beginning of the line (same as Home)
CTRL+e         Go to the End of the line (same as End)
ALT+b / ESC+b  Go one word back (to the left)
ALT+f / ESC+f  Go one word forward (to the right)

# Moving the cursor – one character at a time
CTRL+f         Go forward one character
CTRL+b         Go backward one character

# Using history
CTRL+r         Backwards search in previously executed commands (history)
CTRL+p         Previous command (same as Up arrow)
CTRL+n         Next command (same as Down arrow)

# Deleting whole words
ALT+Del        Delete the word before (to the left of) the cursor
ALT+d / ESC+d  Delete the word after (to the right of) the cursor
CTRL+w         Cut the word before the cursor to the clipboard

# Deleting parts of the line
CTRL+k         Cut the line after the cursor to the clipboard
CTRL+u         Cut/delete the line before the cursor to the clipboard

# Deleting single characters
CTRL+d         Delete character under the cursor (same as Delete key)
CTRL+h         Delete character before the cursor (same as Backspace key)

# Paste, Undo, revert, and more
CTRL+l         Clear the screen (similar to the 'clear' command)
CTRL+y         Paste the last thing to be cut (yank)
CTRL+_         Undo
ALT+r / ESC+r  Revert the changes and replace with the line as it was 
                in History.

# Swap 'em!
CTRL+t         Swap the last two characters before the cursor
ALT+t / ESC+t  Swap current word with previous
 
# Convert to UPPER, lower, or Sentence case
ALT+u / ESC+u  Capitalise characters from the cursor to the end of 
                the current word and move to the end of the word.
ALT+l / ESC+l  Lower the case of characters from the cursor to the
                end of the current word and move to the end of the word.
ALT+c / ESC+c  Capitalize the character under the cursor position 
                and move to the end of the word.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment