Skip to main content
added 16 characters in body
Source Link
αғsнιη
  • 41.9k
  • 17
  • 75
  • 118

hereHere is a long bash line, maybe a bit obscure but workingsolution.

f30days=$(date +%s --date="-30 days");  
for file in 20*.txt; do
    fdate=$(echo $file | tr _ -);
    fsec=$(date +%s --date=${fdate/.txt/});
    if [[ $fsec -lt $f30days ]]; then
        echo "rm $file";$file"
 fi ;  fi
done

I ended it with "echo rm $file""echo rm $file" instead of really deleting your files, this will test the result before...

here is a long bash line, maybe a bit obscure but working.

f30days=$(date +%s --date="-30 days"); for file in 20*.txt; do fdate=$(echo $file | tr _ -); fsec=$(date +%s --date=${fdate/.txt/}); if [[ $fsec -lt $f30days ]]; then echo "rm $file"; fi ; done

I ended it with "echo rm $file" instead of really deleting your files, this will test the result before...

Here is a bash solution.

f30days=$(date +%s --date="-30 days") 
for file in 20*.txt; do
    fdate=$(echo $file | tr _ -)
    fsec=$(date +%s --date=${fdate/.txt/})
    if [[ $fsec -lt $f30days ]]; then
        echo "rm $file"
    fi
done

I ended it with "echo rm $file" instead of really deleting your files, this will test the result before.

Source Link
darxmurf
  • 1.2k
  • 8
  • 21

here is a long bash line, maybe a bit obscure but working.

f30days=$(date +%s --date="-30 days"); for file in 20*.txt; do fdate=$(echo $file | tr _ -); fsec=$(date +%s --date=${fdate/.txt/}); if [[ $fsec -lt $f30days ]]; then echo "rm $file"; fi ; done

I ended it with "echo rm $file" instead of really deleting your files, this will test the result before...