Keep your home directory clean

The du command

Very simple and consize tool to query informations on your home directory. Most useful options are presented, for more check manual page (man du):

$ du -h                # Shows data in human readable units
$ du -s                # Shows a summary: The data of the curent directory as a whole
$ du -d NUM            # Summarizes data in subdirectories down to a maximum depth.
$ du -a                # Also show files in current directory
$ du --exclude PATTERN # It excludes the files whose name matches the pattern

Examples:

$ du -ahd 2              # Show files and directories up to a depth of 2 in human readable units
$ du -a --exclude=*.xyz  # Show all files and directories except .xyz files
$ du -ah | grep G        # dirty hack: show (almost) only files larger than 1 GiB

The find command

Advanced one-line commands to query and change files and directories. It offers many so-called test options and can do actions based on the files and directories it finds.

$ find <directory> <tests> [<actions>]

Actions are optional, if none are given, it prints the list of files. Common usage to find files in directory ‘dir’ larger than 100 MiB:

$ find <dir> -size +100M

A few useful tests:

-name PATTERN          # Allows us to find files whose name matches the PATTERN
-size +nM              # Shows the files larger than n MiB. Use G for GiB
-mtime +/-n            # find files modified more or less than n*24 hours ago

A few useful actions:

-exec <command> {} +   # Execute command on list of files
-exec <command> {} \;  # Execute command on each file in list individually
-delete                # CAREFUL, DATA LOSS! Deletes the files found by the find command

Example: Compress all OUTCAR files in directory ~/calc using xz:

$ find ~/calc -name OUTCAR -exec xz {} +