Created
March 22, 2013 17:00
-
-
Save evilchili/5222964 to your computer and use it in GitHub Desktop.
Deleted the N oldest directories in the current directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# find . -maxdepth 1 -type d -printf '%T@ %p\0' | |
# -- For every directory in the current directory, print a numeric timestamp, a space, the filename, and a null | |
# | |
# sort -z -n | |
# -- Split the output on nulls (-z) and sort numerically (-n) | |
# | |
# gawk 'BEGIN {RS="\0";ORS="\0";FS=" "} NR<=3 {print $2}' | \ | |
# -- Print first (ie, oldest) three filenames in the list, separated by nulls. | |
# | |
# xargs -0 rm -rf | |
# -- for each filename separated by a null (-0), execute 'rm -rf' | |
# | |
find . -maxdepth 1 -type d -printf '%T@ %p\0' | \ | |
sort -z -n | \ | |
gawk 'BEGIN {RS="\0";ORS="\0";FS=" "} NR<=3 {print $2}' | \ | |
xargs -0 rm -rf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment