前言
今天介绍一个 Mac 上非常实用的命令行工具 —— tag。在 Mac 上,我们可以给文件添加标签来进行分类管理,如果你经常需要在 MacOS 上处理文件和目录的标签,那么这个工具将极大地提高你的工作效率。
tag 工具
tag 是一款用于在Mac OS X文件(10.9 Maverick 及更高版本)上操作标签的命令行工具。通过 tag ,你可以高效地添加、删除、设置文件标签,同时也能快速查找带有指定标签的文件。这款工具有以下功能特性:
- 添加/删除/设置文件标签
- 列出文件所有标签
- 查找含有特定标签的所有文件
- 统计各标签的使用情况
- 支持通配符*匹配任意标签
- 可指定搜索范围(家目录/本地磁盘/网络磁盘)
- 支持递归目录操作
- 命令输出可显示文件名/标签/标签颜色等
安装与使用
安装 tag 命令非常简单,你可以通过 MacPorts 或 Homebrew 等包管理器进行安装,也可以手动编译安装。安装后,你将能够使用以下命令来管理你的文件标签:
tag -a | --add:为文件添加标签。tag -r | --remove:从文件移除标签。tag -s | --set:设置文件的标签。tag -m | --match:显示匹配特定标签的文件。tag -l | ---list:列出文件上的标签。tag -f | --find:在整个文件系统中查找带有指定标签的文件。tag -u | --usage:显示标签的使用情况。
以下是 tag 命令帮助信息:
tag - A tool for manipulating and querying file tags.
usage:
tag -a | --add <tags> <path>... Add tags to file
tag -r | --remove <tags> <path>... Remove tags from file
tag -s | --set <tags> <path>... Set tags on file
tag -m | --match <tags> <path>... Display files with matching tags
tag -f | --find <tags> <path>... Find all files with tags, limited to paths if present
tag -l | --list <path>... List the tags on file
tag -u | --usage <tags> <path>... Display tags used, with usage counts
<tags> is a comma-separated list of tag names; use * to match/find any tag.
additional options:
-v | --version Display version
-h | --help Display this help
-A | --all Display invisible files while enumerating
-e | --enter Enter/enumerate directories provided
-R | --recursive Recursively process directories
-n | --name Turn on filename display in output (default)
-N | --no-name Turn off filename display in output (list, find, match)
-t | --tags Turn on tags display in output (find, match)
-T | --no-tags Turn off tags display in output (list)
-g | --garrulous Display tags each on own line (list, find, match)
-G | --no-garrulous Display tags comma-separated after filename (default)
-c | --color Display tags in color
-p | --slash Terminate each directory name with a slash
-0 | --nul Terminate lines with NUL (\0) for use with xargs -0
--home Find tagged files in user home directory
--local Find tagged files in home + local filesystems
--network Find tagged files in home + local + network filesystems
使用示例
- 添加标签:
tag --add work file.txt
- 删除标签:
tag --remove unneeded *.png
- 设置标签(覆盖原有标签):
tag --set new,tags file1.doc file2.xls
- 查找含有特定标签的文件:
tag --find 'project1' ~/Documents
- 列出家目录下所有带标签文件:
tag --tags --garrulous --home
- 查看各标签使用情况:
tag --usage
结语
tag 为我们提供了一种高效、灵活的方式在命令行中管理文件标签。对于经常需要处理大量文件的朋友,tag 绝对是一个必备的好帮手! 想要了解更多或下载 tag,可以访问它的GitHub页面:github.com/jdberry/tag。希望这篇文章对你有所帮助,如果你有任何疑问或想要了解更多实用工具,欢迎留言讨论或者关注我的微信公众号运维小猪,谢谢!!
本文使用 markdown.com.cn 排版