There are several different topics on stackoverflow regarding find/removing the oldest directory/files in a directory . I have read a lot of them and seen a myriad different ways that obviously work for some people on other systems but not for me in my particular case.
The constraints are:
- Im on FreeBSD (Freenas 9.3)
- Directories have spaces in them
- Dont use ls (http://mywiki.wooledge.org/ParsingLs)
- Cannot use -printf of find (doesnt exist for me)
The closest i have gotten is something like this (not complete):
find . -maxdepth 1 -d -name "Backup Set*" -print0 | xargs -0 stat -f "%m %N" | sort -r| awk 'NR>5'
This gives me the directories that I want to delete however they now have timestamps prepended, which I am not sure that if i strip out and pipe to rm i will be back to a situation where i cannot delete directories with spaces in them.
output:
1450241540 ./Backup Set1
1450241538 ./Backup Set0
Thanks for any help here.
relevant posts that I have looked at:
https://superuser.com/questions/552600/how-can-i-find-the-oldest-file-in-a-directory-tree