Skip to content

Instantly share code, notes, and snippets.

@knakayama
Created September 11, 2012 12:20
Show Gist options
  • Save knakayama/3698011 to your computer and use it in GitHub Desktop.
Save knakayama/3698011 to your computer and use it in GitHub Desktop.
でかいファイルはどれですか?
#!/bin/bash
EXCLUDE_DIRS="--exclude={opt,proc,dev,boot,lost+found}"
usage() {
prog_name="$(basename "$0")"
cat << EOF
Usage: $prog_name
Require root privilege
EOF
}
is_root_user() {
local _id="$(id | cut -d' ' -f1 | grep -oE '[0-9]*')"
if [[ "$_id" -eq 0 ]]; then
return 0
else
return 1
fi
}
echo_err() {
echo "ERROR: $1" 2>&1
}
_du() {
#echo "ionice -c2 -n7 nice -n 19 du -s /* --exclude=$EXCLUDE_DIRS | sort -k1n"
#ionice -c2 -n7 nice -n 19 du -s /* "$EXCLUDE_DIRS" | sort -k1n
local _dirs=$(ionice -c2 -n7 nice -n19 du -s /* --exclude={opt,proc,lost+found,dev,boot} | sort -k1n | tail -n 3)
IFS_BAK="$IFS"
IFS=$'\n'
for _dir in ${_dirs[*]}; do
echo "$_dir"
local next_dir=$(echo "$_dir" | cut -d$'\t' -f2)
#echo "$next_dir"
ionice -c2 -n7 nice -n19 du -s ${next_dir}/* | sort -k1n | tail -n3
echo
done
}
restore_ifs_on_exit() {
if [[ -n "$IFS_BAK" ]]; then
IFS="$IFS_BAK"
fi
}
trap restore_ifs_on_exit EXIT
is_root_user
if [[ "$?" -ne 0 ]]; then
echo_err "Require root privilege"
exit 1
fi
_du
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment