Skip to content

Latest commit

 

History

History
429 lines (290 loc) · 10.5 KB

MacOSX_Tips.md

File metadata and controls

429 lines (290 loc) · 10.5 KB

MacOSX

Useful Commands

bash64 decode to hex

$ echo -n 'R1BSVwI=' | base64 -D | hexdump -v -e '/1 "%02x" '
4750525702

xxd

  • xxd <filename> 以16进制显示文件内容
  • xxd -i <filename> 转成c数组
unsigned char note_txt[] = {
  0x0a, 0x0a, 0x0a, 0x35, 0x30, 0x30, 0x30, 0x20, 0x2b, 0x20, 0x37, 0x35,
  0x30, 0x20, 0x70, 0x68, 0x6f, 0x74, 0x6f, 0x0a, 0x31, 0x32, 0x30, 0x20,
  0x20, 0xe5, 0x96, 0x9c, 0xe7, 0xb3, 0x96, 0xe9, 0xa2, 0x84, 0xe4, 0xbb,
  0x98, 0x0a, 0x35, 0x30, 0x30, 0x30, 0x20, 0xe5, 0xb0, 0x8f, 0xe5, 0x8d,
  0x97, 0xe5, 0x9b, 0xbd, 0x20, 0xe5, 0xae, 0x9a, 0xe9, 0x87, 0x91, 0x0a,
  0x0a
};
unsigned int note_txt_len = 61;

mdfind(deprecated)

mdfind

man ascii 字符表

$ man ascii

 The hexadecimal set:

 00 nul   01 soh   02 stx   03 etx   04 eot   05 enq   06 ack   07 bel
 08 bs    09 ht    0a nl    0b vt    0c np    0d cr    0e so    0f si
 ...

cal 日历

  • cal 当月
  • cal -y 当年
  • -j 参数, day 显示为 当年的第几天

打开文件数 / 最大链接数

launchctl limit
sudo launchctl limit maxfiles 100000 500000

sysctl kern.maxfiles
sysctl -w kern.maxfiles=20480 (or whatever number you choose)

# will lost , for centos : /etc/security/limits.conf
ulimit -a
ulimit -n 8192

性能测试

# memory speed
$ dd if=/dev/zero of=/dev/null bs=1m count=32768
32768+0 records in
32768+0 records out
34359738368 bytes transferred in 0.988451 secs (34761195414 bytes/sec)

# explain
# Memory Bandwidth (GB/s)=Memory Clock Frequency (MHz)×Bus Width (bytes)×Transfers per Clock Cycle×10 −3
# for example, 2667MHz, 8bytes, 2 transfers per clock cycle
# Memory Bandwidth(GB/s) = 2667 * 8 * 2 * 10^-3 = 42.672GB/s # 理论内存带宽

内网传输速度测试

1台机器上 开启 iperf3 server

iperf3 -s

另一台机器上 发包测试

iperf3 -c 192.168.1.8 -R

传输速度测试方案2: speedtest

docker run -d --name speedtest -p 0.0.0.0:81:80 adolfintel/speedtest:latest

webpage
http://10.192.89.89:81/

launchd (Ventura)

About crond : "“The cron utility is launched by launchd(8) when it sees the existence of /etc/crontab or files in /usr/lib/cron/tabs. There should be no need to start it manually.”"

There are three main directories you can use with launchd:

  1. /Library/LaunchDaemons
    • job needs to run even when no users are logged in.
  2. /Library/LaunchAgents
    • if the job is only useful when users are logged in.
    • I learned that this has the side-effect of your job being run as 'root' after a system reboot.)
  3. $HOME/Library/LaunchAgents
    • your job will be run under your username.

Create a Mac plist file to describe your job

<?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>com.user.launchVM</string>

  <key>ProgramArguments</key>
  <array>
    <string>/Volumes/WORK/VBoxVDIs/openwrt/launchVM.sh</string>
  </array>

  <key>Nice</key>
  <integer>1</integer>

  <key>StartInterval</key>
  <integer>60</integer>

  <key>RunAtLoad</key>
  <true/>

  <key>StandardErrorPath</key>
  <string>/Volumes/WORK/VBoxVDIs/openwrt/err.log</string>

  <key>StandardOutPath</key>
  <string>/dev/null</string>
</dict>
</plist>

trouble shooting

# list
VBoxManage list runningvms
# stop vm
VBoxManage controlvm openwrt poweroff
# unlock session
vboxmanage startvm openwrt --type emergencystop

# restart
sh /Volumes/WORK/VBoxVDIs/openwrt/launchVM.sh

set permission

cp ./launchVM.plist ~/Library/LaunchAgents/ 
cd ~/Library/LaunchAgents/
sudo chown root ./launchVM.plist
sudo chgrp wheel ./launchVM.plist

load and test it

sudo launchctl bootstrap system  ~/Library/LaunchAgents/launchVM.plist

or just test whether it works:

launchctl load ~/Library/LaunchAgents/launchVM.plist

check SSD lifespan

brew install smartmontools
smartctl -a /dev/disk0

# you may need do some test on disk
smartctl -t short /dev/disk0

screen capture to clipborad

cmd + ctl + shift + 4

screen video capture

cmd + ctl + shift + 5

copy wifi password to clipboard

$ security find-generic-password -wa "ChinaNet-Mebusy" |  pbcopy

find internet password

e.g. find github password

security find-internet-password -s github.com -a your_github_username -w

open finder where specific file exists

open -R <path-to-file>

Easily Find Forgotten Commands from History (bck-i-search)

  1. Open up Terminal.
  2. Type Ctrl-r.
  3. type letters you remember...
  4. As you type, the terminal keeps suggesting a command that matches what you’ve typed.

software update issue

1. software update stuck on restarting...

softwareupdate -l : to see a list of the current updates (to make sure I was updating the same things)
sudo softwareupdate -i -a -R : to install the updates, and restart the computer if required

2. install specific MacOSX version

softwareupdate  --list-full-installers
sudo softwareupdate --fetch-full-installer --full-installer-version 14.7.2 --agree-to-license

v2rayA

  • install

    brew tap v2raya/v2raya
    brew install v2raya/v2raya/v2raya
    brew services start v2raya
  • create server

    • localhost:2017
    • Create a new Server
      • select it in Operations column
      • click start at the top-left corner of the page
  • Settings

    • Transparent Proxy
      • change to Proxy except CN Sites or Proxy only GFWList
    • Mode when Update Subscrition
      • Update all servers and GFWList
        • change to Depend on Rule Port
    • Address and Ports
      • Port of HTTP(with Rule)
        • change to 3128
  • QA

more docs

Add a Route for the Loopback Network , and LAN Network

sudo route add -net 127.0.0.0/8 127.0.0.1
sudo route add -net 192.168.0.0/16 $(route -n get default | grep 'gateway' | awk '{print $2}')

LM Studio

huggingface 换源

$ cd  /Applications/LM Studio.app/Contents/Resources/app/.webpack
$ cat mirror.sh
#!/bin/sh

set -e


# find all .js file in the current directory, and repace 'huggingface co' with 'hf-mirror.com'

find . -type f -name "*.js" -exec sed -i '' 's/huggingface.co/hf-mirror.com/g' {} \;

VMWare 手动挂载共享文件夹

sudo mkdir -p /mnt/hgfs
sudo mount -t fuse.vmhgfs-fuse .host:/ /mnt/hgfs -o allow_other

如果手动挂载 /mnt/hgfs/ 成功,但重启后消失,可以在 /etc/fstab 里添加:

.host:/    /mnt/hgfs    fuse.vmhgfs-fuse    defaults,allow_other    0 0

Downgrade Command Line Tools

  1. remove old version
    sudo rm -rf /Library/Developer/CommandLineTools
  2. download correct CommandLine Tools
  3. check CLTools version:
    $ pkgutil --pkg-info=com.apple.pkg.CLTools_Executables