Mac CLI 指南

终于,Mac 上有了一款能用命令行自由操作各种软件获取各种系统信息的工具 —— Mac CLI,废话不多说,赶紧来看看它的强大威力(但是并不推荐)。


更新记录

  • 2016.09.12: 初稿

安装与删除

安装方式非常简单,一行即可 sh -c "$(curl -fsSL https://raw.githubusercontent.com/guarinogabriel/mac-cli/master/mac-cli/tools/install)"。安装完成之后需要各种配置一下,可以根据个人需要进行选择,我主要挑选了常用的工具类插件,诸如 MySQL 之类的都没有装(因为不需要)

删除的话也是一句 sh -c "$(curl -fsSL https://raw.githubusercontent.com/guarinogabriel/mac-cli/master/mac-cli/tools/uninstall)"

不过之前安装的各种小插件如果有强迫症可能也需要删除

pip uninstall glances
npm uninstall --global fast-cli
brew uninstall pv

其他就看心情随意啦

快速入门

这类工具的使用都是非常简单的(但是功能多了反而有些繁琐),输入 mac list 就可以查看各种命令,非常长,给大家感受一下

# dawang @ wdxtub in ~/Documents/Blog [16-09-12 21:29:11]
$ mac list
 mac CLI – OS X command line tools for developers
====================================================
General Utilities:
mac update: Install OS X software updates, update installed Ruby gems, Homebrew, npm and their installed packages
mac lock: Lock
mac restart: Restart OS X
mac sleep: Sleep mode
mac shutdown: Shutdown
mac time: Show clock at top right position in Terminal/iTerm
mac uptime: Get the time since last restart
mac volume: Get the volume from the terminal
mac volume X: Set the volume from the terminal - X = Level (0-100)
mac volume:mute: Mute volume
mac volume:unmute: Unmute volume
mac volume:ismute: Check if the volume is muted or not
mac screensaver: Start screensaver
mac folders:list: List folders in current directory with their current size
mac folder:size: Calculate current folder size
mac folders:remove-empty: Remove empty subdirectories
mac apps:close-all: Close all opened apps
mac apps:app-store: Get list of installed apps from App Store
mac eject-all: Eject all mounted volumes and disks
mac battery: Get battery information
mac info: Get OS X version information
mac find:text X: Find exact phrase recursively inside directory - X = Text string
mac find:biggest-files : Find biggest files inside directory
mac find:biggest-directories : Find biggest directories inside directory
mac zip:extract X: Extract Zip file to current folder - X = Zip file to extract
mac gzip:compress X: Compress current file using Gzip - X = File to compress
mac gzip:extract X: Extract Gzip file to current folder - X = Gzip file to extract
mac tar:compress X: Compress X file/directory using tar with progress indicator - X = File or directory
mac tar:extract X: Extract tar file to current folder - X = Tar file to extract
Search Utilities:
mac find:recent X: Find files modified in the last N minutes - X = number of minutes
mac search:replace X: Search and replace string in file - X = File to perform the search and replace operation
Network Utilities:
mac speedtest: Internet connection speed test
mac speedtest:infinite: Run internet speed test each 5 minutes
mac ports: List of used ports
mac ip:local: Get local IP address
mac ip:public: Get public IP address
mac dhcp:renew: Renew DHCP Lease
mac dns:clear: Clear DNS Cache
# 省略
LAMP Utilities:
SSH Utilities:
mac ssh:download-file X: Download file from remote server through SSH - X = Path of the remote file to download
mac ssh:download-folder X: Download entire folder from remote server through SSH - X = Path of the remote folder to download
mac ssh:download-database X: Download database from remote server through SSH - X = Name of the database to download
mac ssh:sync:local X: Sync local folder with remote folder using rsync through SSH (download remote folder to local folder)
mac ssh:sync:remote X: Path of the remote folder to sync from local folder (upload local folder to remote folder)
mac ssh:upload X: Upload file to remote server through SSH - X = Path of the file to upload to the remote server
mac ssh:public-key X: Get public SSH key for local machine
Web Development Utilities:
mac dev:monitor X: Monitor file changes (for example: log file) - X = File to monitor
mac dev:optimize-images: Optimize all images in current directory and subdirectories
mac dev:css:convert-to-scss: Convert CSS file to SCSS
Performance and maintenance Utilities:
mac system: Show system information to review mac performance
mac temp: Show temperature, fan and battery statistics
mac memory: See memory usage sorted by memory consumption
mac trash:empty: Empty trash
mac trash:size: Calculate trash size
mac desktop:cleanup: Remove all files and directories from the Desktop directory
mac downloads:cleanup: Remove all files and directories from the Downloads directory
iTerm / Terminal Utilities:
mac iterm:tab-title: Set title to current iTerm tab
Git Utilities:
mac git:config: Display local Git configuration
mac git:open: Open current repository on Github
mac git:create:branch: Create branch based on current branch
mac git:branches:date: Get last update date for all branches in current project
mac git:undo-commit: Undo latest commit
mac git:log: See latest commits IDs and titles for current branch
mac git:branch: See all branches
mac git:branch:rename: Rename Git branch
mac git:branch:remove-local: Remove local Git branch
mac git:branch:remove-remote: Remove local and remote Git branch
mac git:removeecho mac git:branch: See all branches : Remove Git from current project
mac git:config: Check Git settings
mac git:add-removed: Add removed files to staged files
mac git:size: Get size for current Git repository
Web Utilities:
mac web:download-images: Download all images from website to current directory
Homebrew Utilities:
mac brew:update: Upgrade Homebrew, installed Homebrew packages, and cleanup
Xcode Utilities:
mac xcode:cleanup: Cleanup XCode files to free up hard disk space
Image Utilities:
mac image:generate:mobile-app-icons X Y: Generate mobile app icons - X = Path of the original image file, Y= Path of the output file path
# 省略
Magento Utilities:

有这么多命令,而且现在还支持插件,完全可以根据自己的需要来自定义了,不懂的话直接 mac help 即可,非常方便。不过考虑到我的内存有限,还是挑一些我个人觉得比较常用的分享给大家,其他比较鸡肋的就不介绍了(比方说显示个时间什么的,就有点蛋疼了)

常用命令

  • mac update 更新各类软件,包括 ruby gems, homebrew, npm 和对应的包,不过基本需要翻墙
  • mac lock 锁屏,有动画效果
  • mac restart 重启
  • mac sleep 睡眠
  • mac shutdown 关机
  • mac hidden:show 显示隐藏文件
  • mac hidden:hide 关闭显示隐藏文件
  • mac zip:extract filename zip 解压
  • mac gzip:compress [file|folder] gzip 压缩文件/文件夹
  • mac gzip:extract filename gzip 解压
  • mac tar:compress [file|folder] tar 压缩文件/文件夹
  • mac tar:extract filename tar 解压
  • mac speedtest 测试网速
  • mac ports 显示被占用的端口(其实就是 sudo lsof -iTCP -sTCP:LISTEN -P
  • mac ip:local 显示内网 ip(其实就是 ipconfig getifaddr en0
  • mac ip:public 显示外网 ip(其实就是 wget http://ipinfo.io/ip -qO -

总体来说,基本可以认为是把各个常用的命令封装了一次,用统一的接口暴露出来,但是因为我的需求没这么多,其实直接用 zsh 的 alias 就足够了(所以最终我还是删掉了它)

总结

经过短暂的使用,感觉这个工具和我的风格不太符合,比方说明明我用 date 命令就可以获取到当前的时间,为什么还要用 mac time 来呢?明明可以直接 ls -lh 来查看文件大小,为什么要用 mac folders:list 呢?明明可以直接 du -h -d 1 来查看当前文件夹里所有内容的大小,为什么要用 mac folder:size 呢?总有种脱裤子放屁的感觉。

还是更喜欢或许是『莫须有』的对自己电脑的『掌控力』,那么如果觉得这些命令太长太难记,完全可以自己实现一套嘛。我还是喜欢简单一点的语法,命令里有冒号简直是『大逆不道』。

当然,如果是新手,但是又想通过一系列风格统一的命令来(自动化)管理电脑的话,这个还是还可以考虑的。不过相信懂得越多,就越不需要这类看起来很有用的『工具』了吧。

参考链接

广告时间

优秀人才不缺工作机会,只缺适合自己的好机会。但是他们往往没有精力从海量机会中找到最适合的那个。100offer 会对平台上的人才和企业进行严格筛选,让「最好的人才」和「最好的公司」相遇。

点击注册 100offer,谈谈你对下一份工作的期待,收获 5-10 个满足你要求的好机会。

捧个钱场?