Ubuntu文件夹整理实操指南
一、规划与基础操作
二、按规则自动归类与批量处理
mkdir -p Images Videos Documents
find . -maxdepth 1 -type f \( -iname '*.jpg' -o -iname '*.png' \) -exec mv -t Images {} +
find . -maxdepth 1 -type f \( -iname '*.mp4' -o -iname '*.mkv' \) -exec mv -t Videos {} +
find . -maxdepth 1 -type f \( -iname '*.pdf' -o -iname '*.docx' \) -exec mv -t Documents {} +
for f in *; do
[[ -f "$f" ]] || continue
d=$(stat -c %y "$f" | cut -d' ' -f1)
mkdir -p "$d"
mv -i "$f" "$d/"
done
# 将当前目录所有 .txt 重命名为 doc_001.txt, doc_002.txt ...
i=1
for f in *.txt; do
mv -i "$f" "doc_$(printf "%03d" $i).txt"
((i++))
done
find . -type d -empty -delete
find . -name "*.tmp" -print # 先看看会删哪些
find . -name "*.tmp" -delete # 确认无误再执行
三、查找大文件与清理空间
du -h --max-depth=1 | sort -hr | head -20
sudo apt-get install ncdu
ncdu /home
sudo apt-get clean
sudo apt-get autoremove --purge
sudo journalctl --vacuum-time=3d
sudo rm -rf /tmp/*
四、维护与自动化
tar -czf 2025-项目A-归档.tar.gz 2025-项目A/
rsync -av --progress ~/Documents /backup/documents-$(date +%F)