Question : Delete files older than x days, and x characters long.

Hi all,
I'm looking for a bash script that will delete *.txt files that are older then x days whose file names(excluding the .txt extension) are longer than x characters.   Any help would be great!

Thanks,
Matthew.

Answer : Delete files older than x days, and x characters long.

If older means modification time, then:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
#!/bin/sh
 
LENGTH=5
DIR=/your/path
TIME=1
 
for FILE in `find ${DIR} -name "*.txt" -type f -mtime +${TIME}`; do
   NAME=`basename \`echo ${FILE} | sed 's/\.txt$//'\``
 
   if [ `echo -n ${NAME} | wc -c` -gt ${LENGTH} ]; then
      echo rm ${FILE}
   fi
done
Open in New Window Select All
Random Solutions  
 
programming4us programming4us