account
mark account to admin
[!TIP|label:references:]
Copy $ sudo dscl . -merge /Groups/admin GroupMembership < usernam e >
remove account from admin
[!NOTE|label:references:]
Copy $ sudo dscl . -delete /Groups/admin GroupMembership < usernam e >
# or
$ sudo dseditgroup -o edit -d < usernam e > -t user admin
modify SHELL
Copy # for current account
$ chsh -s $( command -v bash )
$ sudo bash -c "echo $( command -v bash ) >> /etc/shells"
# or for `<username>`
$ sudo chsh -s $( command -v bash ) < usernam e >
$ sudo bash -c "echo $( command -v bash ) >> /etc/shells"
check account
check admin accounts
Copy $ sudo dscl . -read /Groups/admin GroupMembership
GroupMembership: root _avectodaemon marslo
check account info
Copy $ dscacheutil -q user -a name marslo
name: marslo
password: ********
uid: 503
gid: 20
dir: /Users/marslo
shell: /usr/local/bin/bash
gecos: Marslo Jiao
# or
$ sudo dscl . -read /Users/marslo
read account from plist
Copy $ sudo defaults read /var/db/dslocal/nodes/Default/users/ < accoun t > .plist
check account AuthenticationAuthority
Copy $ sudo dscl . -read /Users/ < usernam e > AuthenticationAuthority
AuthenticationAuthority: ; ShadowHash ; HASHLIST: <SALTED-SHA512-PBKDF2,SRP-*******-****-SHA512-PBKDF2> ; Kerberosv5 ;; marslo@LKDC:SHA1.37************************************83 ; LKDC:SHA1.37************************************83 ; ; SecureToken ;
$ sudo dscl . -read /Users/ < usernam e > AltSecurityIdentities
AltSecurityIdentities:
X509: <T>CN=Apple Root CA,OU=Apple Certification Authority,O=Apple Inc.,C=US < S > CN=com.apple.idms.appleid.prd.00****-**-********-****-****-****-**********e9
check account policy
Copy $ sudo dscl . -read /Users/ < usernam e > dsAttrTypeNative:accountPolicyData
dsAttrTypeNative:accountPolicyData:
< ?xml version= "1.0" encoding= "UTF-8" ?>
<! DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd" >
< plist version = "1.0" >
< dict >
< key > creationTime </key>
< real > 1730235857.0728331 </real>
< key > failedLoginCount </key>
< integer > 0 </integer>
< key > failedLoginTimestamp </key>
< integer > 0 </integer>
< key > passwordLastSetTime </key>
< real > 1730752335.9585528 </real>
< /dict >
< /plist >
list all accounts
[!NOTE|label:references:]
Copy $ sudo dscl . -list /Users
# or
$ sudo dscl . -list /Users GeneratedUID
# or
$ sudo dscacheutil -q user
[!TIP]
using diskutil list
to get disk info
guest account
create guest and enable
[!NOTE|label:references:]
scripts: https://github.com/sheagcraig/guestAccount/blob/master/guest_account
Copy $ dscl . -create /Users/Guest
# keychain
$ keychain= '/Users/Guest/Library/Keychains/login.keychain'
$ security create-keychain -p '' $keychain
$ security login-keychain -s $keychain
disable guest account
Copy $ sudo dscl . delete /Users/Guest
$ sudo defaults write /Library/Preferences/com.apple.AppleFileServer guestAccess -bool NO
$ sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server AllowGuestAccess -bool NO
$ sudo defaults write /Library/Preferences/com.apple.loginwindow GuestEnabled -bool FALSE
# remove Other
$ sudo defaults write /Library/Preferences/com.apple.loginwindow SHOWOTHERUSERS_MANAGED -bool FALSE
or
Copy $ sudo /usr/sbin/sysadminctl -deleteUse Guest
check status
Copy $ sysadminctl -guestAccount status
2020-12-30 20:27:59.524 sysadminctl[45327:844298] Guest account disabled.
$ sudo sysadminctl -guestAccount off
2020-12-30 20:28:39.645 sysadminctl[45479:846930] Guest account is already disabled
add account
as admin
Copy $ sudo sysadminctl -addUser < usernam e > -password < passwor d > -admin
as normal user
Copy $ sysadminctl -addUser < usernam e > -fullName "<full name>" -password "<password>" -hint "<hint>"
system tools
hostinfo
Copy $ hostinfo
Mach kernel version:
Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020 ; root:xnu-6153.141.2~1/RELEASE_X86_64
Kernel configured for up to 12 processors.
6 processors are physically available.
12 processors are logically available.
Processor type: x86_64h (Intel x86-64h Haswell )
Processors active: 0 1 2 3 4 5 6 7 8 9 10 11
Primary memory available: 16.00 gigabytes
Default processor set: 463 tasks, 2557 threads, 12 processors
Load average: 2.72, Mach factor: 9.26
Copy $ paste <( vm_stat | awk 'NR>1' | grep -o ".*:") <( for i in $( vm_stat | awk 'NR>1' | tr -d '.' | awk '{print $NF}'); do perl -e "print $i/1024" | awk '{printf "%0.2f", $0}'; echo ; done) | column -s: -t
Pages free 328.70
Pages active 910.00
Pages inactive 973.38
Pages speculative 39.51
Pages throttled 0.00
Pages wired down 852.52
Pages purgeable 389.65
"Translation faults" 174323.38
Pages copy-on-write 7828.62
Pages zero filled 127404.04
Pages reactivated 3420.56
Pages purged 6392.20
File-backed pages 656.69
Anonymous pages 1266.20
Pages stored in compressor 2536.76
Pages occupied by compressor 991.23
Decompressions 1555.85
Compressions 8494.54
Pageins 7799.75
Pageouts 11.98
Swapins 43.15
Swapouts 48.46
show system info
show memory
iStat
Copy $ istats
--- CPU Stats ---
CPU temp: 53.19°C ▁▂▃▅▆▇
--- Fan Stats ---
Total fans in system: 2
Fan 0 speed: 2157 RPM ▁▂▃▅▆▇
Fan 1 speed: 1995 RPM ▁▂▃▅▆▇
--- Battery Stats ---
Battery health: unknown
Cycle count: 34 ▁▂▃▅▆▇ 3.4%
Max cycles: 1000
Current charge: 6093 mAh ▁▂▃▅▆▇ 100%
Maximum charge: 6237 mAh ▁▂▃▅▆▇ 85.0%
Design capacity: 7336 mAh
Battery temp: 36.5°C
For more stats run ` istats extra ` and follow the instructions.
show adapter
Copy $ pmset -g adapter # or `pmset -g ac`
Wattage = 140W
Current = 4990mA
Voltage = 28000mV
AdapterID = 28697
Manufacturer = Apple Inc.
Family Code = 0xe000400a
Serial String = C4H430307PCQ41CA4
Adapter Name = 140W USB-C Power Adapter
Hardware Version = 1.0
Firmware Version = 01040073
show charge status
Copy $ pmset -g ps # or `pmset -g batt`
Now drawing from 'AC Power'
-InternalBattery-0 (id=66125923) 100%; charged; 0:00 remaining present: true
$ pmset -g rawbatt
12/12/2024 04:06:55
AC; Not Charging; 100%; Cap=100: FCC=100; Design=8579; Time=0:00; 0mA; Cycles=6/1000; Location=0;
Polled boot=12/11/2024 17:43:05; Full=12/12/2024 04:03:30; User visible=12/12/2024 04:06:30
$ system_profiler SPPowerDataType | sed -n '/Charge Information:/,/System Power Settings:/p' | sed '$d'
Charge Information:
The battery’s charge is below the warning level: No
Fully Charged: Yes
Charging: No
State of Charge (%): 100
Health Information:
Cycle Count: 6
Condition: Normal
Maximum Capacity: 100%
$ system_profiler SPPowerDataType | grep -A11 "AC Charger Information"
AC Charger Information:
Connected: Yes
ID: 0x7019
Wattage (W): 140
Family: 0xe000400a
Serial Number: C4H430307PCQ41CA4
Name: 140W USB-C Power Adapter
Manufacturer: Apple Inc.
Hardware Version: 1.0
Firmware Version: 1040073
Charging: No
show Mach virtual memory statistics
check process without interactive mode
example
Copy $ top -l 1 -n 0
Processes: 472 total, 3 running, 469 sleeping, 2589 threads
2020/11/02 16:10:28
Load Avg: 2.67, 2.88, 3.12
CPU usage: 33.4% user, 20.46% sys, 46.49% idle
SharedLibs: 268M resident, 69M data, 44M linkedit.
MemRegions: 112888 total, 3016M resident, 90M private, 2802M shared.
PhysMem: 16G used (3742M wired ), 420M unused.
VM: 3201G vsize, 1993M framework vsize, 44188 ( 0 ) swapins, 49627 ( 0 ) swapouts.
Networks: packets: 1575080/1561M in, 1302980/954M out.
Disks: 1368885/28G read, 648911/13G written.
show system
Serial Number
Copy $ /usr/sbin/system_profiler SPHardwareDataType
Hardware:
Hardware Overview:
Model Name: MacBook Pro
Model Identifier: MacBookPro15,1
Processor Name: 6-Core Intel Core i7
Processor Speed: 2.2 GHz
Number of Processors: 1
Total Number of Cores: 6
L2 Cache (per Core ): 256 KB
L3 Cache: 9 MB
Hyper-Threading Technology: Enabled
Memory: 16 GB
Boot ROM Version: 10**.***.*.*.* (iBridge: 17.**.*****.*.*,* )
Serial Number (system): ************
Hardware UUID: ********-****-****-****-************
Activation Lock Status: Enabled
hardware
cpu manufacture
Copy $ sysctl -n machdep.cpu.brand_string
Intel(R ) Core( TM ) i7-8750H CPU @ 2.20GHz
or
Copy $ sysctl machdep.cpu
machdep.cpu.max_basic: 22
machdep.cpu.max_ext: 2147483656
machdep.cpu.vendor: GenuineIntel
machdep.cpu.brand_string: Intel ( R ) Core ( TM ) i7-8750H CPU @ 2.20GHz
machdep.cpu.family: 6
...
memory
Copy $ system_profiler SPHardwareDataType | grep "Memory:\|Cores:\|Processors:"
Number of Processors: 1
Total Number of Cores: 6
Memory: 16 GB
or
Copy $ sysctl hw.memsize
hw.memsize: 17179869184
$ sysctl hw.ncpu
hw.ncpu: 12
memory slot
Copy $ system_profiler SPMemoryDataType
Memory:
Memory Slots:
ECC: Disabled
Upgradeable Memory: No
BANK 0/ChannelA-DIMM0:
Size: 8 GB
Type: DDR4
Speed: 2400 MHz
Status: OK
Manufacturer: Micron
Part Number: **********-*****
Serial Number: -
BANK 2/ChannelB-DIMM0:
Size: 8 GB
Type: DDR4
Speed: 2400 MHz
Status: OK
Manufacturer: Micron
Part Number: **********-*****
Serial Number:
Copy $ sysctl vm.swapusage
vm.swapusage: total = 1024.00M used = 34.00M free = 990.00M (encrypted)
Copy $ sysctl kern.version
kern.version: Darwin Kernel Version 20.1.0: Sat Oct 31 00:07:11 PDT 2020 ; root:xnu-7195.50.7~2/RELEASE_X86_64
$ sysctl kern.ostype
kern.ostype: Darwin
$ sysctl kern.osrelease
kern.osrelease: 20.1.0
$ sysctl kern.osrevision
kern.osrevision: 199506
or
Copy $ uname -a
Darwin iMarslo 20.1.0 Darwin Kernel Version 20.1.0: Sat Oct 31 00:07:11 PDT 2020 ; root:xnu-7195.50.7~2/RELEASE_X86_64 x86_64 i386 MacBookPro15,1 Darwin
Copy $ lpstat -a
printer-01 accepting requests since Wed Feb 3 16:40:50 2021
plist file
read file
Copy $ plutil -p /path/to/file.plist
# i.e.:
$ plutil -p /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Info.plist
$ /usr/libexec/PlistBuddy -c print /path/to/file.plist
# i.e.:
$ /usr/libexec/PlistBuddy -c print /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Info.plist
osx installation
Copy $ softwareupdate --fetch-full-installer
or
Copy $ softwareupdate --fetch-full-installer --full-installer-version **.**.*
# i.e.:
$ softwareupdate --fetch-full-installer --full-installer-version 10.15
MacOS Mojave 10.14.6 Installer
Copy $ softwareupdate --fetch-full-installer --full-installer-version 10.14.6
MacOS Catalina 10.15.3 Installer
Copy $ softwareupdate --fetch-full-installer --full-installer-version 10.15.3
MacOS High Sierra 10.13.6 Installer
Copy $ softwareupdate --fetch-full-installer --full-installer-version 10.13.6
for Catalina FINAL version
Copy $ sudo /Applications/Install \ macOS \ Catalina.app/Contents/Resources/createinstallmedia --volume /Volumes/UNTITLED && echo Catalina Boot Drive Created
for Catalina BETA version
Copy $ sudo /Applications/Install \ macOS \ Catalina \ Beta.app/Contents/Resources/createinstallmedia --volume /Volumes/UNTITLED && echo Catalina Boot Drive Created
boot with macOS USB installer
connect the macOS Catalina 10.15 beta install drive to to the Mac you want to install Catalina onto
immediately hold down the OPTION key upon boot, keep holding Option until you see the boot menu
choose the macOS Catalina 10.15 beta installer volume to boot from
download MacOS Mojave installer , or the MacOS Catalina installer (or the installer you wish to turn into an ISO) from the Mac App Store, untill the “Install MacOS Mojave.app” or “Install MacOS Catalina.app” application is fully downloaded and within the /Applications folder, proceed
open the Terminal application, create a disk image DMG file via:
Copy $ hdiutil create -o /tmp/Mojave -size 8500m -volname Mojave -layout SPUD -fs HFS+J
mount the created DMG disk image via:
Copy $ hdiutil attach /tmp/Mojave.dmg -noverify -mountpoint /Volumes/Mojave
use createinstallmedia to create the macOS installer application on the mounted volume:
Copy $ sudo /Applications/Install \ macOS \ Mojave.app/Contents/Resources/createinstallmedia --volume /Volumes/Mojave --nointeraction
unmount the volume just created:
Copy $ hdiutil detach /volumes/Install \ macOS \ Mojave
convert the DMG disk image file to an ISO disk image file (technically a CDR file but it’s the same as an iso)
Copy $ hdiutil convert /tmp/Mojave.dmg -format UDTO -o ~/Desktop/Mojave.cdr
rename the CDR file extension to ISO to convert the CDR to ISO:
Copy $ mv ~/Desktop/Mojave.cdr ~/Desktop/Mojave.iso
flushed
[!NOTE|label:references:]
disk cache
flush DNS
[!NOTE|label:references:]
Copy $ sudo killall -HUP mDNSResponder
# or
$ sudo dscacheutil -flushcache ; sudo killall -HUP mDNSResponder ; say cache flushed
ventura & monterey
Copy $ sudo dscacheutil -flushcache ; sudo killall -HUP mDNSResponder
lion, mountain lion, mavericks, el capitan, sierra, high sierra, mojave
Copy $ sudo killall -HUP mDNSResponder
yosemite
Copy $ sudo discoveryutil mdnsflushcache
tiger
Copy $ lookupd -flushcache
clean OSX native dot file
Copy $ dot_clean -mvp < pat h >
i.e.:
Copy $ sudo dot_clean -mvp /
or
Copy $ /usr/local/bin/rg --hidden --smart-case --color=never --files "$HOME" -g '*\.DS_*' | xargs -r rm
# or
$ /usr/local/bin/fd -Iu --glob '*\.DS_*' $HOME | xargs -r rm
$ find $HOME -name '.DS_Store' -type f -delete
# or
$ find / -name '._*' -type f -delete
# or
$ find / -name '._*' -type f -size -4k -delete
or all-in-all actions
[!NOTE|label:references:]
Copy $ sudo defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
$ sudo mdutil -i off /Volumes/ < FS NAM E >
$ sudo rm -rf .{DS_Store,fseventsd,Spotlight-V*,Trashes}
for windows
Copy > cd c:\path\to\folder
> del /s /q /f /a .DS_STORE
> del /s /q /f /a:h ._*
launchctl
create new plist
Copy $ cat > ~/Library/LaunchAgents/i.marslo.updatedb.plist << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>i.marslo.updatedb</string>
<key>ProgramArguments</key>
<array>
<string>sudo</string>
<string>/usr/local/bin/gupdatedb</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/Users/marslo/.marslo/log/i.marslo.updatedb.log</string>
<key>StandardOutPath</key>
<string>/Users/marslo/.marslo/log/i.marslo.updatedb.error.log</string>
<key>StartInterval</key>
<integer>300</integer>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
EOF
check
Copy $ plutil ~/Library/LaunchAgents/i.marslo.updatedb.plist
/Users/marslo/Library/LaunchAgents/i.marslo.updatedb.plist: OK
enable
Copy $ launchctl load ~/Library/LaunchAgents/i.marslo.updatedb.plist
$ launchctl list | grep updatedb
- 1 i.marslo.updatedb
disable
Copy $ launchctl remove i.marslo.updatedb
Q&A
SUPreferenceManager: Failed to set object of class: __NSCFString
issue:
Copy $ softwareupdate --fetch-full-installer
Downloading and installing com.apple.InstallAssistant.macOSBigSur installer
SUPreferenceManager: Failed to set object of class: __NSCFString for key: LastRecommendedMajorOSBundleIdentifier with error: Error Domain=SUPreferenceManagerErrorDomain Code= 1 "(null)"
SUPreferenceManager: Failed to set object of class: __NSCFString for key: LastRecommendedMajorOSBundleIdentifier with error: Error Domain=SUPreferenceManagerErrorDomain Code= 1 "(null)"
SUPreferenceManager: Failed to set object of class: __NSCFString for key: LastRecommendedMajorOSBundleIdentifier with error: Error Domain=SUPreferenceManagerErrorDomain Code= 1 "(null)"
Installing: 90.0%SUPreferenceManager: Failed to set object of class: __NSCFString for key: LastRecommendedMajorOSBundleIdentifier with error: Error Domain=SUPreferenceManagerErrorDomain Code= 1 "(null)"
Install failed with error: 0