Advanced Finder operations: tag management, Quick Look, file information, smart folders.
Use Cases
- User says "tag these files" or "preview this file"
- User needs to view detailed file information (size, creation time, etc.)
- User needs to filter files by criteria
Command Reference
File Tags (macOS Tags)
# 给文件打标签
tag -a "重要" /path/to/file.pdf
# 或者用 xattr
xattr -w com.apple.metadata:_kMDItemUserTags '("重要")' /path/to/file.pdf
View file tags
mdls -name kMDItemUserTags /path/to/file.pdf
Search files by tagmdfind "kMDItemUserTags == 'Important'"
Remove tagtag -r "Important" /path/to/file.pdf
### Quick Look 预览
```bash
# 预览文件(按空格关闭)
qlmanage -p /path/to/file.pdf
# 生成缩略图
qlmanage -t /path/to/file.pdf -s 512 -o /tmp/
Detailed File Information
# 完整元数据
mdls /path/to/file.pdf
# 常用字段
mdls -name kMDItemDisplayName -name kMDItemFSSize -name kMDItemContentCreationDate -name kMDItemContentModificationDate -name kMDItemKind /path/to/file.pdf
# 人类可读的文件大小
stat -f "大小: %z bytes" /path/to/file.txt
du -sh /path/to/file.txt
# 文件类型
file /path/to/file
Disk space
# 磁盘总体使用
df -h /
# 当前目录大小
du -sh .
# 子目录大小排序(前 10)
du -sh */ 2>/dev/null | sort -rh | head -10
Recently used files
# 最近修改的 20 个文件
mdfind "kMDItemFSContentChangeDate >= $time.today(-1)" -onlyin ~ | head -20
# 最近打开的文件(通过 Finder recents)
mdfind "kMDItemLastUsedDate >= $time.today(-7)" -onlyin ~/Documents | head -20
Folder statistics
# 统计文件数量和类型
find /path/to/dir -type f | sed 's/.*\.//' | sort | uniq -c | sort -rn
# 统计总文件数
find /path/to/dir -type f | wc -l
Output Specifications
- File sizes in human-readable format (KB/MB/GB)
- Times in natural language such as "X days ago" or "just now"
- Confirm results after tag operations
- Display disk space using a concise table