account

mark account to admin

[!TIP|label:references:]

$ sudo dscl . -merge /Groups/admin GroupMembership <username>
  • remove account from admin

    [!NOTE|label:references:]

    $ sudo dscl . -delete /Groups/admin GroupMembership <username>
    
    # or
    $ sudo dseditgroup -o edit -d <username> -t user admin
    

modify SHELL

# 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) <username>
$ sudo bash -c "echo $(command -v bash) >> /etc/shells"

check account

  • check admin accounts

    $ sudo dscl . -read /Groups/admin GroupMembership
    GroupMembership: root _avectodaemon marslo
    
  • check account info

    $ 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

    $ sudo defaults read /var/db/dslocal/nodes/Default/users/<account>.plist
    
  • check account AuthenticationAuthority

    $ sudo dscl . -read /Users/<username> 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/<username> 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

    $ sudo dscl . -read /Users/<username> 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:]

$ sudo dscl . -list /Users

# or
$ sudo dscl . -list /Users GeneratedUID

# or
$ sudo dscacheutil -q user

[!TIP]

  • using diskutil list to get disk info
check which user is using the disk
1.7.3.1 -- check which user is using the disk

guest account

create guest and enable

[!NOTE|label:references:]

$ dscl . -create /Users/Guest

# keychain
$ keychain='/Users/Guest/Library/Keychains/login.keychain'
$ security create-keychain -p '' $keychain
$ security login-keychain -s $keychain

enable root user

Enable Root User
1.7.3.2 -- Enable Root User

disable guest account

$ 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

    $ sudo /usr/sbin/sysadminctl -deleteUse Guest
    
  • check status

    $ 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

    $ sudo sysadminctl -addUser <username> -password <password> -admin
    
  • as normal user

    $ sysadminctl -addUser <username> -fullName "<full name>" -password "<password>" -hint "<hint>"
    

system tools

hostinfo

$ 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

get human-readable vm_stat

$ 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

$ glances

show memory

$ top -o MEM

iStat

 $ 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

$ 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

    $ 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

$ vm_stat

check process without interactive mode

$ top -l 1 -n 0
  • example

    $ 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.
    
  • or

    $ top -l 1 -s 0
    

show system

Serial Number

$ /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
    $ sysctl -n machdep.cpu.brand_string
    Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    
    or
    $ 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

$ system_profiler SPHardwareDataType | grep  "Memory:\|Cores:\|Processors:"
      Number of Processors: 1
      Total Number of Cores: 6
      Memory: 16 GB
  • or

    $ sysctl hw.memsize
    hw.memsize: 17179869184
    
    $ sysctl hw.ncpu
    hw.ncpu: 12
    

memory slot

$ 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:

swap usage

$ sysctl vm.swapusage
vm.swapusage: total = 1024.00M  used = 34.00M  free = 990.00M  (encrypted)

show kernel version

$ 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
    $ 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
    

list printer status

$ lpstat -a
printer-01 accepting requests since Wed Feb  3 16:40:50 2021

plist file

  • read file

    $ 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

download older version

$ softwareupdate --fetch-full-installer
  • or

    $ softwareupdate --fetch-full-installer --full-installer-version **.**.*
    
    # i.e.:
    $ softwareupdate --fetch-full-installer --full-installer-version 10.15
    
  • MacOS Mojave 10.14.6 Installer

    $ softwareupdate --fetch-full-installer --full-installer-version 10.14.6
    
  • MacOS Catalina 10.15.3 Installer
    $ softwareupdate --fetch-full-installer --full-installer-version 10.15.3
    
  • MacOS High Sierra 10.13.6 Installer
    $ softwareupdate --fetch-full-installer --full-installer-version 10.13.6
    

create osx installer usb

  • for Catalina FINAL version
    $ sudo /Applications/Install\ macOS\ Catalina.app/Contents/Resources/createinstallmedia --volume /Volumes/UNTITLED && echo Catalina Boot Drive Created
    
  • for Catalina BETA version
    $ 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
  • reboot the Mac
  • 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

Convert a MacOS Installer to ISO

  • 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:

    $ hdiutil create -o /tmp/Mojave -size 8500m -volname Mojave -layout SPUD -fs HFS+J
    
  • mount the created DMG disk image via:

    $ hdiutil attach /tmp/Mojave.dmg -noverify -mountpoint /Volumes/Mojave
    
  • use createinstallmedia to create the macOS installer application on the mounted volume:

    $ sudo /Applications/Install\ macOS\ Mojave.app/Contents/Resources/createinstallmedia --volume /Volumes/Mojave --nointeraction
    
  • unmount the volume just created:

    $ 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)

    $ hdiutil convert /tmp/Mojave.dmg -format UDTO -o ~/Desktop/Mojave.cdr
    
  • rename the CDR file extension to ISO to convert the CDR to ISO:

    $ mv ~/Desktop/Mojave.cdr ~/Desktop/Mojave.iso
    

flushed

[!NOTE|label:references:]

disk cache

$ sudo purge

flush DNS

[!NOTE|label:references:]

$ sudo killall -HUP mDNSResponder
# or
$ sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder; say cache flushed
  • ventura & monterey

    $ sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
    
  • lion, mountain lion, mavericks, el capitan, sierra, high sierra, mojave

    $ sudo killall -HUP mDNSResponder
    
  • yosemite

    $ sudo discoveryutil mdnsflushcache
    
  • tiger

    $ lookupd -flushcache
    

clean OSX native dot file

$ dot_clean -mvp <path>
  • i.e.:

    $ sudo dot_clean -mvp /
    
  • or

    $ /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 disable indexing

    $ sudo mdutil -i off /Volumes/<diskName>
    
  • or all-in-all actions

    [!NOTE|label:references:]

    $ sudo defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
    $ sudo mdutil -i off /Volumes/<FS NAME>
    $ sudo rm -rf .{DS_Store,fseventsd,Spotlight-V*,Trashes}
    
  • for windows

    > cd c:\path\to\folder
    > del /s /q /f /a .DS_STORE
    > del /s /q /f /a:h ._*
    
  • flush DNS

    $ ipconfig /flushdns
    

launchctl

create new plist

$ 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
    $ plutil ~/Library/LaunchAgents/i.marslo.updatedb.plist
    /Users/marslo/Library/LaunchAgents/i.marslo.updatedb.plist: OK
    
  • enable
    $ launchctl load ~/Library/LaunchAgents/i.marslo.updatedb.plist
    $ launchctl list | grep updatedb
    - 1 i.marslo.updatedb
    
  • disable
    $ launchctl remove i.marslo.updatedb
    

Q&A

SUPreferenceManager: Failed to set object of class: __NSCFString

  • issue:
    $ 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
    
Copyright © marslo 2020-2024 all right reserved,powered by GitbookLast Modified: 2024-12-12 04:20:45

results matching ""

    No results matching ""