Mac OS Commands

Here’s a cheatsheet of some commonly used Mac OS commands. There are too many to list all of them, these just scratch the surface.

#MD5 HASH:
md5 -s "my string value"

#SCP AS BG PROCESS: no hang up, pause process using ctrl+z, bg to resume in background
nohup scp -p -r user@192.168.0.100:/volume1/tmp/my-folder . > nohup.out 2>&1
ctrl+z
bg

#SYMBOLIC LINK:
ln -s /path/to/source target

#CURL:
curl -I http://google.com
curl -L -v http://google.com > dump.out 2>&1
curl -x www-proxy.us.abc.com:80 http://google.com

#ZIP and TAR:
zip -r archive.zip folder1 folder2
zip -er encrypted.zip folder1
unzip -l archive.zip
tar -zcvf archive.tar.gz folder1 folder2
tar -ztvf archive.tar.gz
tar -zxvf archive.tar.gz

#REFACTOR:
find . -type f -name "*Controller.php" -print0 xargs -0 sed -i 's/string1/string2/g'

#GREP:
grep -r -i --exclude='*\.svn*'  "string1" .

#FIND:
find . -type f -name '.DS_Store' -delete
rm -rf `find . -type d -name .git`
find . -type d -name .svn -exec rm -rf {} \;

#LINUX MEM:
top (shift m)
cat /proc/meminfo
free -m

#set JAVA_HOME to 1.7 or 1.8
#  run these commands to see results:
#  /usr/libexec/java_home -v 1.7
#  /usr/libexec/java_home -v 1.8
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)

#PHOTO RESIZE:
sips -Z 800 *.jpg
sips --resampleWidth 800 *.jpg
#!/bin/bash
for i in *.heic; do sips -s format jpeg "${i}" --out "${i%heic}jpg"; done

#PHOTO APPEND (ImageMagick):
convert +append  a.jpg b.jpg ab.jpg  //horizontal append
convert -append  a.jpg b.jpg ab.jpg  //vertical append

#MOVIE CONVERSION:
brew install ffmpeg
ffmpeg formats
ffmpeg -i file.mov file.mp4
ffmpeg -i file.mov -vf scale=-2:1080 file.mp4
ffmpeg -i input.mov -qscale 0 -r 30 -y output.mov

#COCOAPODS
cd project_dir
pod init
vi Podfile
  platform :ios, '8.0'
  ...
  pod 'Firebase/Core'
  ...
pod repo update
pod install/update
launch XCode using myapp.xcworkspace

#HOMEBREW
brew update
brew doctor
brew outdated
brew upgrade
brew cleanup
brew ls -l
brew ls --versions
brew search spark
brew services list
brew services start postgresql@16
brew services stop postgresql@16
brew tap
brew tap homebrew/php
brew untap homebrew/php
brew tap caskroom/cask
brew cask list
brew install Caskroom/cask/xquartz

#HOMEBREW RESET
sudo chown -R whoami /usr/local
cd /usr/local
git fetch origin
git reset --hard origin/master

#AWSCLI
aws configure list      #list default profile
aws configure           #configure default profile
aws s3 ls
aws s3 ls s3://bucket-name
aws s3 cp ./local-file.txt s3://bucket-name          #no cost
aws s3 cp s3://bucket-name/file.txt ./local-file.txt #network cost
aws s3 rm s3://bucket-name/file.txt

TOP COMMAND

  • Set memory scale - E then e
  • Add new column for threads (nTH)
  • Enter Fields-Management - f
  • Navigate to column RES - down-arrow
  • Set sort by - s
  • Navigate to column nTH - down-arrow
  • Select column - right-arrow
  • Move column up - up-arrow
  • Toggle column selection - d
  • Save settings - W
  • Exit - q