Mac Unix

Mac Unix

by John Vincent


Posted on February 14, 2017


This stuff ends up sprayed everywhere, so let's create a reference document.

Various

Find and delete

find . -name ‘*.class' -delete
find . -name “*.class” -exec rm {} \;

find . | grep .git | xargs rm -rf
find . -name "*.pdf" -exec chown someuser:somegroup {} \;

Find and exclude

find . -type f -name "utils.js" ! -path "*/node_modules/*" | more

List space used by node_modules

find . -name "node_modules" -type d -prune -print | xargs du -chs

Remove node_modules

find . -name 'node_modules' -type d -prune -print -exec rm -rf '{}' \;

List directories as a tree

tree -I node_modules

excludes node_modules folder

List directory sizes by disk usage

du -sch

du -a . | sort -rn | head -20

Total disk use

find . -type f -print0 | xargs -0 stat -f'%z' | awk '{b+=$1} END {print b}'

Show the size of a single file

du -h path_to_a_file

Show the size of the contents of a directory, each sub-directory, and each individual file:

du -h path_to_a_directory

Show the size of the contents of a directory:

du -sh path_to_a_directory

Recursively list files with sizes sorted by largest sizes first.

find . -type f -print0 | xargs -0 stat -f '%z %N' | sort -rn | more

Root Alias

Add to /var/root/.profile

. /Users/jv/Desktop/MyDevelopment/github/repo_shell_scripts/mac/.root_bash_profile

where .root_bash_profile

#!/bin/bash
#

echo "Running /Users/jv/Desktop/MyDevelopment/github/repo_shell_scripts/mac/.root_bash_profile"

lf() { ls -FaC $*; }

alias ls='ls -GFh'

Use

sudo su -

What is my IP?

dig @ns1.google.com -t txt o-o.myaddr.l.google.com +short
dig -4 @ns1-1.akamaitech.net -t a whoami.akamai.net +short
dig -4 @resolver1.opendns.com -t a myip.opendns.com +short

Add SSH keys

cd
cd .ssh

ls to list keys

ssh-add -k id_digital_ocean
ssh-add -k id_github

Terminal

New Tab Command T

To auto complete

cd abc<tab>

Move forward / backward one word

opt left arrow, right arrow.

Beginning of line

ctrl A

end of line

ctrl E

clear screen

ctrl k

Finder

Rename a folder: Click the folder and hold over it. Name will become editable.

New Tab; Command T

New Window; from anywhere, Command N

Disk Space

find . -name “node_modules" -print
find . -type d -name "node_modules" -exec rm -rf '{}' +

Since 30 days ago

find . -mtime -30 -name "*.js" -exec ls -l {} \;

Screen Saver

Control + Shift + Eject or Power

Shutdown

Command + Shift + Eject or Power

Screen Snapshot

  • Full screen: Command Shift 3
  • Partial screen: Command Shift 4

Save .png file to desktop.

Can drag and drop into Evernote.

Record Screen

Shift + Command + 5

Multiple Desktops

  • F3 (desktops)
  • Mouse to top right
  • Plus sign appears
  • Click it

Remove Desktop

  • F3 (desktops)
  • hover over desktop
  • X appears top left
  • Click it

Move to Another Desktop

  • F3 (desktops)
  • Drag window to the desktop

Add a Desktop

  • F3 (desktops)
  • Far right, a + will appear
  • Click it to add a desktop

Network Utility

  • Command+Spacebar to summon Spotlight
  • type "Network Utility" followed by the return key to launch the Network Utility app

Mac Quarantine

jar files downloaded from the internet are automatically set to quarantine.

To see this

xattr -l file

To clear this

xattr -d com.apple.quarantine my_jar.jar
xattr -dr

Show Hidden Files

  • Terminal
  • defaults write com.apple.finder AppleShowAllFiles YES
  • killall Finder

Enable Zoom

  • Apple, System Preferences
  • Accessibility

Notice

  • Toggle zoom: Shift Command 8
  • Zoom out: Shift Command +
  • Zoom in: Shift Command -

Open Ports

lsof -i | grep LISTEN

Evernote Mac Keys

Paste as Plain Text: Command Shift V

Make a Spec

  • Make screen shots and save to desktop.

  • Using Paint X Lite,

  • Drag images to extra large canvas, re-align them and save as .png to desktop.

  • Start Skitch

    • New file (Screen Snap, Blank)
    • Drag the image onto Skitch

Now can add text etc.

Save in Skitch (Evernote).

Combine PDFs with Brother Printer/Scanner

  • Arrange pages in order.
  • Place in feed print side up and top of document towards to the feeder.

Open Control Center

  • Scan
  • File
  • Check; Continuous Scanning
  • Start Scanning - will scan all the pages
  • Finish

The PDF is created on the desktop.

LibreOffice ODT to PDF

libreoffice --headless --convert-to pdf *.odt

or

  • Open with LibreOffice
  • Export
    • pdf

Connect to Windows

For example, connect to remote windows host gamma

  • open terminal
  • cd /etc
  • sudo vi /etc/hosts
  • add ip to gamma

Should now be able to ping.

  • Open new Finder Windows
  • Finder menu
  • Go
  • Connect to Server
    • smb://gamma/

Should now connect to server, now authenticate

  • connect as: registered user
  • name: john
  • password:

Will show volumes to mount

  • mount as needed

Format USB Stick

Applications, Utilities, Disk Utility

  • Select Device
  • Erase

This should work.

If get error

Couldn't modify partition map

find the path of the USB

diskutil list

and erase the USB device /dev/disk5

diskutil eraseDisk ExFAT USBNAME /dev/disk5

App not appearing in Launchpad or out of date

cd "~/Library/Application Support/Dock

Delete *.db files

rm *.db

and reboot.

Kill Process on Port

Port is in use.

lsof -i -P | grep {port-number}

or

lsof -i:{port-number}

provides the process id.

kill -9 {process-id}

Increase Node memory

node --max-old-space-size=1024 index.js #increase to 1gb
node --max-old-space-size=2048 index.js #increase to 2gb
node --max-old-space-size=3072 index.js #increase to 3gb
node --max-old-space-size=4096 index.js #increase to 4gb
node --max-old-space-size=5120 index.js #increase to 5gb
node --max-old-space-size=6144 index.js #increase to 6gb
node --max-old-space-size=7168 index.js #increase to 7gb
node --max-old-space-size=8192 index.js #increase to 8gb

Using the environment

NODE_OPTIONS="--max-old-space-size=4096"

Archived

Mac Update - check the following

Ethernet connection fails.

Reinstall

/Users/jv/Desktop/MyDownloads/mac/AX88179_178A_Macintosh_10.6_to_10.12_Driver_Installer_v2.8.0_20161108/AX88179_178A.dmg

Install and restart.