Skip to content

Instantly share code, notes, and snippets.

@annagapuz
Last active June 21, 2022 14:20
Show Gist options
  • Save annagapuz/4657369 to your computer and use it in GitHub Desktop.
Save annagapuz/4657369 to your computer and use it in GitHub Desktop.
Helpful *nix Commands- truncate, delete file/directories based on age, df, du
# Number indicates size, in bytes, to leave. Can run on a file that is currently being written to, like server logs.
sudo truncate -s 4 server.log
# Deletes files and directories older than 7 days
sudo find <full path dir> -ctime +7 -exec rm -rf {} \;
# Disk space
df
df -h // human-readable
# Disk usage
du -sk * | sort -n // sort, ascending order
du -sh * // human-readable
du -hs $(ls -A) // show hidden files and directories
# Look for files bigger then 100MB:
find . -size +100000000c -ls
22615 483984 -rw-r--r-- 1 root other 495339455 Dec 14 15:09 ./mail/access_log
113593 209784 -rw-r--r-- 1 root other 214696853 Dec 14 15:08 ./mail/servletd.log
208492 354768 -rw-rw-rw- 1 admin mail 363091751 Dec 14 14:29 ./mail/admin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment