Linux sed on macOS
Install gnu sed
brew install gnu sed
Create an alias that will replace macOS built-in sed
echo "alias sed=gsed" >> ~/.zshrc
Install gnu sed
brew install gnu sed
Create an alias that will replace macOS built-in sed
echo "alias sed=gsed" >> ~/.zshrc
Open the sudo utility
sudo vi /etc/pam.d/sudo
Add the following as the first line
auth sufficient pam_tid.so
defaults write com.apple.PowerChime ChimeOnNoHardware -bool true
killall PowerChime
Start an x86_64 emulated shell, every command is also emulated.
arch -x86_64 zsh
macOS stopped updating bash and switched to zsh. You can install bash with:
brew install bash
After that point bash -version should print version 5. In your scripts you should not reference /bin/bash anymore but env.
#!/usr/bin/env bash
Check if binary is quarantined
xattr bin/cache/artifacts/libimobiledevice/idevice_id
Remove binary from quarantine
sudo xattr -d com.apple.quarantine bin/cache/artifacts/libimobiledevice/idevice_id
Remove all attributes
sudo xattr -c bin/cache/artifacts/libimobiledevice/idevice_id
Disable indexing on all connected drives.
sudo mdutil -a -i off
Reboot
Enable indexing /
sudo mdutil -i on /
Erase and rebuild index
sudo mdutil -E /
Debug Spotlight
sudo mddiagnose
sudo spctl --master-disable
alternative: control-click on it and choose Open
You can not disable local Time Machine snapshots, but you can remove them like this:
tmutil listlocalsnapshotdates / | grep 20 | while read f; do tmutil deletelocalsnapshots $f; done
Run this once and it puts all the apps downloaded from the App Store into the TM exclude.
mdfind "kMDItemAppStoreHasReceipt=1" -onlyin /Applications/ | while read x; do sudo tmutil addexclusion -p "$x"; done
It may be the cause of high CPU usage in the background.
defaults write com.apple.iPhoto PKFaceDetectionEnabled 0
If you want to use the SF Mono font you can find it inside the Terminal app.
open /Applications/Utilities/Terminal.app/Contents/Resources/Fonts/
launchctl unload -w /System/Library/LaunchAgents/com.apple.gamed.plist
and
defaults write com.apple.gamed Disabled -bool true
launchctl unload -w /System/Library/LaunchAgents/com.apple.rcd.plist
List the connected disks.
diskutil list
Overwrite the disk with zeros.
diskutil secureErase 0 /dev/diskX
ifconfig | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}'
There is a cool app for this called Sloth, or in the Terminal:
lsof -P -i -n
lsof -i tcp:8000
networksetup -setsocksfirewallproxy "Wi-Fi" localhost 8080; ssh -N -D 8080 USER@IPADDRESS -pSSHPORT; networksetup -setsocksfirewallproxystate "Wi-Fi" off
brew install youtube-dl youtube-dl --ignore-errors -f mp4 https://www.youtube.com/watch?v=dQw4w9WgXcQ afconvert -d aac input.mp4 output.m4a
If you want 1080p mp4 to be your default add the following line to ~/.config/youtube-dl/config.
-i -f 'bestvideo[height<=1080][ext=mp4]+bestaudio[ext=m4a]/best[height<=1080][ext=mp4]/best'
open -na /Applications/Skype.app --args -DataPath /Users/$(whoami)/Library/Application\ Support/Skype2
To disable System Integrity Protection boot into the Recovery partition by pressing cmd+R at startup. Open Utilities > Terminal and run:
csrutil disable
For this to work you need to disable system integrity protection.
defaults write com.apple.Safari NSUserKeyEquivalents -dict-add Back "\U232b"
Right click in the home folder, select "Show View Options", at the bottom you can enable "Show Library Folder"
Alternative you can press: shift-cmd-. to show hidden files.
Screenshot file format and change extension to lowercase
sudo killall -HUP mDNSResponder
defaults write NSGlobalDomain NSDocumentSaveNewDocumentsToCloud -bool false
defaults write com.apple.finder AppleShowAllFiles true
defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false
stay awake
caffeinate -i
prevent display sleep
caffeinate -d
Prevent Mac from falling asleep for an hour
caffeinate -u -t 3600
sudo tmutil disablelocal
defaults write -g ApplePressAndHoldEnabled -bool false
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3
sudo mdutil -E -p "/Volumes/Macintosh HD"
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain user;killall Finder
Screenshot file format and change extension to lowercase
defaults write com.apple.screencapture type png
Screenshot name
defaults write com.apple.screencapture name ScreenShot
Screenshot Location
defaults write com.apple.screencapture location [path]
defaults write com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool true
defaults write com.apple.spotlight DictionaryLookupEnabled NO
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
defaults write com.apple.helpviewer DevMode -bool true
press ⌘2 after
open /System/Library/CoreServices/Applications/Wireless\ Diagnostics.app
defaults write com.apple.dock mcx-expose-disabled -bool false;killall Dock
defaults write com.apple.dashboard mcx-disabled -boolean YES;killall Dock
log out and log back in after
sudo defaults write /System/Library/LaunchAgents/com.apple.notificationcenterui KeepAlive -bool false
defaults write com.apple.dock single-app -bool true;killall Dock
sudo nvram SystemAudioVolume=%80
Format it for macOS and then use fsck_hfs with "-S" for scanning.
diskutil list diskutil unmountDisk /dev/diskXXXX sudo fsck_hfs -fy -S /dev/diskXXXX (press ctrl-t for progress)
For example replacing png with webp:
f="test file.png" noExt=${f%.*} echo $noExt newExt="$noExt".webp echo $newExt
f="test file.png" dc="$(GetFileInfo -d "$f")" # store creation date dm="$(GetFileInfo -m "$f")" # store modification date # change the file here SetFile -d "$dc" "$f" # restore creation date SetFile -m "$dm" "$f" # restore modification date
Start a webserver that publishes the current directory
python -m http.server 8000
or
php -S 0.0.0.0:8000
Wakeup Reason
log show |grep -i "Wake reason"
gzip
tar -czf folder_name.tar.gz folder_name/
Open screen sharing
open vnc://computername.local
Enable screen sharing
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.screensharing.plist
Open current folder in Finder
open .
Restart Finder
killall Finder
Restart Dock
killall Dock
Network Monitor
lsof -ni -P
Display all locations of a binary
type -a git
⌃⌘Q (control + command + Q) to lock screen