Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script shell

Status
Not open for further replies.

Variable86

Technical User
Nov 25, 2011
2
0
0
Hi, how can I compress all the directories that don't contain
at least one file used in the last 15 days , with the same name of the directory

thank you
 
What have you tried so far and where in your code are you stuck ?
Hint: man find

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
my idea was to search all directories and then search the directories with file that has been accessed last month and then i don't how to make the difference between two results ( i don't know even if it's possibile )
 
Something like this?

#!/bin/bash

if [ -z $1 ]
then
echo -e "\nNeed the number of days to go back to!\n"
echo "Example;"
echo "$0 15"
echo -e "Will go back 15 days"
exit 1;
fi

dt1=$(date "+%s" )
reftm=$(echo "$1*24*3600" |bc)

let "newtm=$dt1-$reftm"

for d in $(ls -l |grep "^d" |awk '{print $8}')
do
dtime=$(date -r $d "+%s" )
if [ $dtime -ge $newtm ]
then
echo "backing up $d"
tar -cvzf $d.tgz $d
fi
done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top