Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.83 KB | None | 0 0
  1.   #!/bin/bash
  2.  
  3.   if [ $# != 1 ] ; then
  4.       echo "Usage: sh $0 /path/to/sort/dir"
  5.       exit 1;
  6.   fi
  7.  
  8.   WORK_DIR=$1
  9.  
  10.   # sort all xml files by subdirs, named by date of file
  11.   find -- $WORK_DIR -maxdepth 1 -type f -name "*.xml"|
  12.       {  
  13.           while read filename
  14.           do
  15.  
  16.               file_date=`date -r "$filename" "+%Y-%m-%d"`
  17.               file_path=`dirname "$filename"`
  18.  
  19.               mkdir -p "$file_path/$file_date"
  20.               mv "$filename" "$file_path/$file_date"
  21.           done
  22.       }  
  23.  
  24.   # archive all dirs older 13 days (and remove after)
  25.   find -- $WORK_DIR -maxdepth 1 -type d -mtime +13 \
  26.       -exec tar -czf "{}.tar.gz" {} \; -exec rm -rf {} \;
  27.  
  28.   # delete tar archives older than a month
  29.   find -- $WORK_DIR -maxdepth 1 -name "*.tar.gz" -mtime +30 -delete
  30.  
  31.   exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement