Skip to content

Instantly share code, notes, and snippets.

@JustinTW
Last active March 31, 2017 01:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JustinTW/a3388b7536a65a6a2c100aab29edf030 to your computer and use it in GitHub Desktop.
Save JustinTW/a3388b7536a65a6a2c100aab29edf030 to your computer and use it in GitHub Desktop.
Linux 大量檔案操作 Cheatsheets (最快速的方法蒐集)

產生檔案

產生 1000 個 500kb 的隨機檔案

for i in {1..100000}; do head -c 500 /dev/urandom > dummy$i; done

產生隨機內容大檔案 (1G)

dd if=<(openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt < /dev/zero) of=filename bs=1M count=1000 iflag=fullblock

刪除

刪除大量檔案的目錄

  • 方法1(最快)
cd yourdirectory
perl -e 'for(<*>){((stat)[9]<(unlink))}'
  • 方法2(次快)
mkdir empty_dir
rsync -a --delete empty_dir/    yourdirectory/

查詢

Inode 用量

find / -xdev -printf '%h\n' | sort | uniq -c | sort -k 1 -n

檔案數量

for t in files links directories; do echo `find . -type ${t:0:1} | wc -l` $t; done 2> /dev/null

查詢最常使用的 20 個指令

history | awk '{print $2;}' | sort | uniq -c | sort -rn | head -20

參考資料

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment