Skip to content

Instantly share code, notes, and snippets.

@oranblackwell
Last active August 9, 2019 15:14
Show Gist options
  • Save oranblackwell/7a933c96621d132f976fa2793d4ec44f to your computer and use it in GitHub Desktop.
Save oranblackwell/7a933c96621d132f976fa2793d4ec44f to your computer and use it in GitHub Desktop.
A number of linux directory commands useful for tidying up your media library
A number of linux directory commands useful for tidying up your media library

Find and list all directories whose contents is less then a particular size.

For example, say you want to scan your TV Shows Library to find any directories which only contain an image and an ampty season folder but no video files.

find . -mindepth 1 -maxdepth 1 -type d -exec du -ms {} + | awk '$1 <= 50' | cut -f 2-

if satisfied, add the following to delete all those directories

| xargs -d \\n rm -rf

Find and list all directories which contain more then 1 file bigger then X size.

For example, say you want to scan your Movies library to find any directories which may have 2 or more copies of that movie - a conventional "Sort by Dir Size" approach could show you directories with only 1 large file.

find . -type d ! -empty \
-exec sh -c 'count=$(find "$1" -type f -size +100M | wc -l); [ $count -ge 2 ]' _ {} \; -print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment