Home rotation of file in shell script

# rotation of file in shell script

Rups
1#
Rups Published in 2014-03-25 09:31:51Z
 I need to write rotation of files shell script. I have following format data in a target directory(/backup/store_id/dates_folders) Like : cd /backup/ drwxr-xr-x 5 root root 4096 Mar 25 12:30 44 drwxr-xr-x 3 root root 4096 Mar 25 12:30 45 drwxr-xr-x 4 root root 4096 Mar 25 12:30 48 drwxr-xr-x 3 root root 4096 Mar 25 12:30 49 cd /backup/44/ drwxr-xr-x 2 root root 4096 Mar 25 12:30 22032014 drwxr-xr-x 2 root root 4096 Mar 25 12:30 23032014 drwxr-xr-x 2 root root 4096 Mar 25 12:30 24032014 drwxr-xr-x 2 root root 4096 Mar 25 12:30 25032014 now 44 (store_id) contain four dates folders. I want each store_id( like 44 folder) contain only three recent dates folder like 23,24,25 & 22 should be deleted. Please help me how to write in shell script. Please give me some hint
MarcoS
2#
 This should work: cd /backup && ls -d */ | while read storeId; do rm -r ls -r \$storeId | tail -3; done  I assume here that directory names are more important than their timestamps... If that is not the case, you should use ls -tr instead of ls -r, to let ls command sort on timestamps...