bash - How to grep for new folders which don't match folders from the pattern -
i need following in bash:
go folder , recursively check new files in current folder, new files last update time >=d - 7 days, remember name of every new files
i this: find ./ -type f -ctime -7 -exec ls {} \; > new.files
then need go previous directory cd ../
, find new folders created not white list (the list of folders) , updated during last 7 days. if find directory need go directory , check new files did before (find ./ -type f -ctime -7 -exec ls {} \; > new.files.from.new.dir
)
as result should send list of new files , list of new directories (not white list) new files.
thank in advance help!
here's finished, refined script! note cool use of redirection. :)
#!/bin/bash ##################### # # file change finder # #################### #export use in shells! export curr_dir=`pwd` results_loc=$curr_dir whitelists_loc=$curr_dir period=0.1 #before x number of days... can fractional #also, needed shells, hence source export ftime=-$period #make list of new files in current dir. if [ -e $whitelists_loc/whitelist.files ]; # what's going on here: # # 1. inner shells change current dir., search change files, w # 3 diff. types of mods. # # 2. output sorted, , piped uniq -d give single # items duplicates. merged duplicate set # of calls gives uniq items via uniq -u. # # 3. lastly, apply pertinent grep file filters remove (-v -f) # in case of whitelist, or select (as in case of # our new dir. ((sort <(cd $curr_dir && find . -type f -ctime $ftime) \ <(cd $curr_dir && find . -type f -atime $ftime) \ <(cd $curr_dir && find . -type f -mtime $ftime) | uniq -d) && \ (sort <(cd $curr_dir && find . -type f -ctime $ftime) \ <(cd $curr_dir && find . -type f -atime $ftime) \ <(cd $curr_dir && find . -type f -mtime $ftime) | uniq -u))| \ grep -v -f $whitelists_loc/whitelist.files > \ $curr_dir/new.files else ((sort <(cd $curr_dir && find . -type f -ctime $ftime) \ <(cd $curr_dir && find . -type f -atime $ftime) \ <(cd $curr_dir && find . -type f -mtime $ftime) | uniq -d) && \ (sort <(cd $curr_dir && find . -type f -ctime $ftime) \ <(cd $curr_dir && find . -type f -atime $ftime) \ <(cd $curr_dir && find . -type f -mtime $ftime) | uniq -u)) > \ $curr_dir/new.files fi #go down dir, requested cd ../ working_dir=`pwd` #store list of new dirs (can removed later, if desired. ((sort <(cd $working_dir && find . -type d -ctime $ftime) \ <(cd $working_dir && find . -type d -atime $ftime) \ <(cd $working_dir && find . -type d -mtime $ftime) | uniq -d) && \ (sort <(cd $working_dir && find . -type d -ctime $ftime) \ <(cd $working_dir && find . -type d -atime $ftime) \ <(cd $working_dir && find . -type d -mtime $ftime) | uniq -u)) > \ $results_loc/new.dir #safely select conditions based on whether whitelist file , new.dir #file exist. # #this gives result want -- new files in new dirs. if [ -e $whitelists_loc/whitelist.dir ]; if [ -e $results_loc/new.dir ]; echo "1" ((sort <(cd $working_dir && find . -type f -ctime $ftime) \ <(cd $working_dir && find . -type f -atime $ftime) \ <(cd $working_dir && find . -type f -mtime $ftime) | uniq -d) && \ (sort <(cd $working_dir && find . -type f -ctime $ftime) \ <(cd $working_dir && find . -type f -atime $ftime) \ <(cd $working_dir && find . -type f -mtime $ftime) | uniq -u)) | grep -f $results_loc/new.dir \ grep -v -f $whitelists_loc/whitelist.files > \ $results_loc/new.files.from.new.dir else echo "2" ((sort <(cd $working_dir && find . -type f -ctime $ftime) \ <(cd $working_dir && find . -type f -atime $ftime) \ <(cd $working_dir && find . -type f -mtime $ftime) | uniq -d) && \ (sort <(cd $working_dir && find . -type f -ctime $ftime) \ <(cd $working_dir && find . -type f -atime $ftime) \ <(cd $working_dir && find . -type f -mtime $ftime) | uniq -u)) |\ grep -v -f $whitelists_loc/whitelist.files > \ $results_loc/new.files.from.new.dir fi else if [ -e $results_loc/new.dir ]; echo "3" ((sort <(cd $working_dir && find . -type f -ctime $ftime) \ <(cd $working_dir && find . -type f -atime $ftime) \ <(cd $working_dir && find . -type f -mtime $ftime) | uniq -d) && \ (sort <(cd $working_dir && find . -type f -ctime $ftime) \ <(cd $working_dir && find . -type f -atime $ftime) \ <(cd $working_dir && find . -type f -mtime $ftime) | uniq -u)) | \ grep -f $results_loc/new.dir > \ $results_loc/new.files.from.new.dir else echo "4" ((sort <(cd $working_dir && find . -type f -ctime $ftime) \ <(cd $working_dir && find . -type f -atime $ftime) \ <(cd $working_dir && find . -type f -mtime $ftime) | uniq -d) && \ (sort <(cd $working_dir && find . -type f -ctime $ftime) \ <(cd $working_dir && find . -type f -atime $ftime) \ <(cd $working_dir && find . -type f -mtime $ftime) | uniq -u)) > \ $results_loc/new.files.from.new.dir fi fi
...sorry version posted earlier non-working, made super-cool new version, building on basic idea original.
Comments
Post a Comment