Skip to content

Instantly share code, notes, and snippets.

@smashedlife
Last active January 4, 2016 21:29
Show Gist options
  • Save smashedlife/8680839 to your computer and use it in GitHub Desktop.
Save smashedlife/8680839 to your computer and use it in GitHub Desktop.
Useful Linux commands

Delete all files older than X days

find /path/to/base/dir -type d -ctime +10 -exec rm -fr {} \;

What it all does:

  • find: the unix command for finding files /directories / links etc.
  • /path/to/base/dir: the directory to start your search
  • type d: only find directories
  • ctime +10: only consider the ones with modification time older than 10 days
  • exec … ;: for each such result found, do the following command in …
  • rm -fr {}: recursively force remove the directory; the {} part is where the find result gets substituted into from the previous part.

List space in each partition

df -h 

List by sort order with newest on the bottom

ls -ntr

Find largest 10 files/directories

du -hsx /PATH/TO/DIR | sort -rh | head -10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment