root directory
根目录,/
home directory
家目录,/Users/账户名称,使用~
表示
working directory
当前目录,使用.
表示
parent directory
当前目录的上一级目录,使用..
表示
*
匹配任意字符任意次数
?
匹配任意字符一次
显示当前目录,绝对路径
ls [-ABCFGHLOPRSTUW@abcdefghiklmnopqrstuwx1] [file ...]
展示file。如果没有指定file,那么展示当前目录内容(不包括隐藏文件)。如果file为文件,那么展示文件名。如果file为目录,那么展示目录内容(不包括隐藏文件)
//展示当前目录所有条目(包括以.开头命名的条目)ls -a//展示当前目录所有条目(包括以.开头命名的条目,除了.和..)ls -A
改变当前目录。如果没有指定目录,那么改变当前目录为home目录
//以相对路径方式,改变当前目录为桌面cd Desktop//以绝对路径方式,改变当前目录为桌面cd ~/Desktop//返回上级目录cd ..
制造目录
//当制造Test目录时,显示详细信息mkdir -v Test
移除目录(目录必须为空)
//移除Test目录rmdir Test
cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_filecp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file ... target_directory
-f
: 如果文件只读,那么移除只读文件并且创建一个新的文件-i
: 当覆盖时,提示是否覆盖一个已经存在的文件-n
: 不覆盖一个已经存在的文件
//复制test.txt到copy.txtcp test.txt copy.txt//复制test.txt到Test目录cp test.txt Test///如果文件只读,那么移除只读文件并且创建一个新的文件cp -f test.txt Test/test.txt//提示是否覆盖一个已经存在的文件cp -i test.txt Test/test.txt//不覆盖一个已经存在的文件cp -n test.txt Test/test.txt
mv [-f | -i | -n] [-v] source filemv [-f | -i | -n] [-v] source ... directory
-i
: 当覆盖时,提示是否覆盖一个已经存在的文件-n
: 不覆盖一个已经存在的文件
//移动test.txt到Test目录重命名为foo.txtmv test.txt Test/foo.txt//移动test.txt到Test目录mv test.txt Test///如果Foo存在,那么移动Test目录到Foo目录,如果Foo不存在,那么Test目录重命名为Foo目录mv Test Foo//提示是否覆盖一个已经存在的文件mv -i test.txt Test/foo.txt//不覆盖一个已经存在的文件mv -n test.txt Test/foo.txt
rm [-dfiPRrvW] file ...
移除文件,不能移除目录
-d
: 移除文件和目录(目录必须为空)-R等于-r
: 移除文件和目录
//移除Test目录rm -R / -r Test
值得注意的是 : 谨慎使用rm -R
或者rm -r
,如果路径为.
,那么当前目录清空
如果文件不存在,那么创建文件
//创建test.txttouch test.txt
打开文件或者目录
//打开test.txtopen test.txt//打开Foo目录open Foo//打开当前目录open .
以管理员身份执行一次命令
访问macOS的user defaults系统,user defaults是不是非常熟悉,没错,访问iOS的user defaults系统通过NSUserDefaults.standardUserDefaults
。这里主要说下read和write
defaults [-currentHost | -host hostname] read [domain [key]]defaults [-currentHost | -host hostname] read-type domain keydefaults [-currentHost | -host hostname] write domain { 'plist' | key 'value' }
read
: 获得所有domain的所有偏好read domain
: 获得domain的所有偏好read domain key
: 通过domain的key获得valueread-type domain key
: 通过domain的key获得value类型write domain key value
: 通过domain的key设置valuedomains
: 显示user defaults系统所有domain
指定domains
domain
: 域名,com.apple.dt.Xcode-app application
: 可以指定domain,-app Xcodefilepath
: 任意plist文件路径可以指定domain,/Applications/Xcode.app/Contents/Info.plist
指定value types
如果没有指定value types,默认为string。这里主要说下array和dict
-array
: 对于给定的key,key对应的value为array,允许用户设置array-array-add
: 对于给定的key,key对应的value为array,允许用户添加新元素
//设置names数组defaults write /Users/YJ/Desktop/Info.plist names -array "Kiryu"//添加新元素defaults write /Users/YJ/Desktop/Info.plist names -array-add "Majima"
-dict
: 对于给定的key,key对应的value为dict,允许用户设置dict-dict-add
: 对于给定的key,key对应的value为dict,允许用户添加新键值
//设置emails字典defaults write /Users/YJ/Desktop/Info.plist emails -dict "Kiryu" "Kiryu@qq.com"//添加新键值defaults write /Users/YJ/Desktop/Info.plist emails -dict-add "Majima" "Majima@qq.com"
值得注意的是 : Shell中,如果字符串包含空格,那么必须使用单引号或者双引号。单引号不保留字符的特殊含义,双引号保留字符的特殊含义
结合实际
//是否显示所有文件defaults write com.apple.finder AppleShowAllFiles -bool YES / NO//获得Applications目录Xcode的UUIDdefaults read /Applications/Xcode.app/Contents/Info.plist DVTPlugInCompatibilityUUID
说下Xcode的UUID和插件
Xcode 5.0之后,苹果添加了UUID验证。插件的user defaults,DVTPlugInCompatibilityUUIDs(key)应该包含Xcode的DVTPlugInCompatibilityUUID,否则插件无法工作。不同插件的安装路径可能不同
VVDocumenter
/Users/YJ/Library/Application Support/Developer/Shared/Xcode/Plug-ins/VVDocumenter-Xcode.xcplugin/Contents/Info.plist
KSImageNamed
/Users/YJ/Library/Developer/Xcode/Plug-ins/KSImageNamed.ideplugin/Contents/Info.plist
找到所有插件的安装路径,通过defaults一步到位
//VVDocumenter添加UUIDdefaults write /Users/YJ/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins/VVDocumenter-Xcode.xcplugin/Contents/Info.plist DVTPlugInCompatibilityUUIDs -array-add "$(defaults read /Applications/Xcode.app/Contents/Info.plist DVTPlugInCompatibilityUUID)"//KSImageNamed添加UUIDdefaults write /Users/YJ/Library/Developer/Xcode/Plug-ins/KSImageNamed.ideplugin/Contents/Info.plist DVTPlugInCompatibilityUUIDs -array-add "$(defaults read /Applications/Xcode.app/Contents/Info.plist DVTPlugInCompatibilityUUID)"
联系客服