← 返回
未分类 中文

File Management

Perform safe file and directory operations on Unix systems using built-in tools for listing, searching, reading, organizing, and managing without external bi...
在 Unix 系统上使用内置工具进行安全的文件与目录操作,包括列表、搜索、读取、整理和管理,无需外部二进制依赖。
tyronecoh tyronecoh 来源
未分类 clawhub v1.0.2 1 版本 99836.9 Key: 无需
★ 0
Stars
📥 1,224
下载
💾 2
安装
1
版本
#file-management#filesystem#latest#macos#safe#security#unix-tools

概述

File Management

Safe filesystem operations using only pre-installed system tools. No external dependencies, no network access, no install.

Core Principle

Safety first — always confirm destructive operations before executing.

  • mv, cp, rm are irreversible without a backup
  • Prefer ls -la before touching anything
  • For deletions, prefer trash (macOS) or rm as last resort

Built-in Tools Only

Guaranteed on all Unix/macOS

ToolPurposeNotes
----------------------
lsList filesAll Unix ✅
findSearch filesAll Unix ✅
grepSearch file contentsAll Unix ✅
cat / head / tailRead filesAll Unix ✅
mvMove / renameWrite ⚠️
cpCopy filesWrite ⚠️
mkdirCreate directoriesWrite ⚠️
rmDelete filesWrite ⚠️ last resort
statFile metadataAll Unix ✅
duDisk usageAll Unix ✅
tarArchive filesAll Unix ✅
xattrExtended attributesmacOS ✅

macOS-specific (pre-installed)

ToolPurposeNotes
----------------------
trashMove to Trash (recoverable)macOS ✅ preferred
pbcopy / pbpasteClipboardmacOS ✅
mdlsSpotlight metadatamacOS ✅
mdutilSpotlight indexmacOS ✅

Optional tools (may not be installed)

These are helpful but NOT guaranteed. Check with which before using:

  • tree — directory tree view (install: brew install tree)
  • rg (ripgrep) — faster grep (install: brew install ripgrep)
  • fd — faster find (install: brew install fd)
  • dust — better du (install: brew install dust)
  • bat — better cat (install: brew install bat)

Common Patterns

List Directory Contents

# Basic listing
ls -la /path/to/dir

# Human-readable sizes, newest first
ls -lahF /path/to/dir | sort -k5 -rh

# Recursive depth
find /path -maxdepth 2 -type f

# Show hidden files
ls -la /path/to/dir

Search for Files by Name

# Find by name pattern
find /path -name "*.txt" -type f

# Case-insensitive
find /path -iname "readme*"

# Modified in last N days
find /path -name "*.md" -mtime -7

# By size
find /path -size +100M

Search File Contents

# Grep with context
grep -rn "search_term" /path

# Case-insensitive
grep -ri "search_term" /path

# Only filenames with matches
grep -rl "search_term" /path

Disk Usage Analysis

# Total size of directory
du -sh /path/to/dir

# Per-subdirectory breakdown
du -h --max-depth=1 /path | sort -rh

# Find largest files (recursive)
find /path -type f -exec du -h {} + | sort -rh | head -20

Move / Copy / Delete

# Move (rename)
mv source.txt /new/path/

# Copy (recursive for directories)
cp -r /source/dir /dest/dir

# Delete — ALWAYS confirm first
# Preferred on macOS (goes to Trash):
trash /path/to/file.txt
# Or rm as last resort:
rm /path/to/file.txt

Batch Rename (pure bash)

# Rename all .txt to .md in current directory
for f in *.txt; do mv "$f" "${f%.txt}.md"; done

# Replace spaces with underscores
for f in *\ *; do mv "$f" "${f// /_}"; done

Archive & Compress

# Create tar.gz
tar -czvf archive.tar.gz /path

# Extract
tar -xzvf archive.tar.gz

# Create zip
zip -r archive.zip /path

# Extract zip
unzip archive.zip

Permission Model

Read-only operations — safe to execute without asking:

ls, find, grep, cat, head, tail, du, stat, file, mdls

Write operations — always confirm before executing:

mv, cp, mkdir, trash, rm, zip, tar

For destructive operations:

  1. Show what will be affected first
  2. Ask for confirmation with exact command
  3. Prefer trash over rm on macOS

Anti-Patterns (Never Do)

  • rm -rf / or any recursive delete without confirming
  • chmod -R 777 or permission changes that break security
  • ❌ Executing downloaded scripts directly without review
  • ❌ Accessing paths outside user's home without asking
  • sudo operations unless explicitly requested

Quick Reference

# Where am I?
pwd

# What's in current directory?
ls -la

# Find all PDFs larger than 10MB
find ~ -name "*.pdf" -size +10M

# How much space is used?
du -sh ~/Library

# Search for TODO in code files
grep -rn --include="*.py" "TODO" ~/code/

版本历史

共 1 个版本

  • v1.0.2 当前
    2026-05-03 03:31 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

ai-agent

Image Prompt Engineer

tyronecoh
专业摄影提示工程技能,用于AI图像生成。适用于Midjourney、DALL·E、Stable Diffusion、Flux等平台的提示词生成及产品摄影等场景。
★ 0 📥 800
dev-programming

Mcporter

steipete
使用 mcporter CLI 直接列出、配置、认证及调用 MCP 服务器/工具(支持 HTTP 或 stdio),涵盖临时服务器、配置编辑及 CLI/类型生成功能。
★ 195 📥 67,678
dev-programming

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 678 📥 327,598