Operating System - Linux
1830250 Members
3465 Online
110000 Solutions
New Discussion

Need "find" command arguments to seek our ASCII/TEXT files that...

 
SOLVED
Go to solution
Alzhy
Honored Contributor

Need "find" command arguments to seek our ASCII/TEXT files that...

are at least 5MB, and have not been modified for 30 days.

The idea is to seek out ASCII/TEXT files that are hugely compressible and flag/compress them.

Points will be aptly rewarded.

Hakuna Matata.
7 REPLIES 7
A. Clay Stephenson
Acclaimed Contributor

Re: Need "find" command arguments to seek our ASCII/TEXT files that...


cd to desired starting directory then:

#!/usr/bin/sh
find . -type f -mtime +30 -size +10240 | while read F
do
file "${F}" | grep -i -q "text"
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
rm "${F}"
fi
done
-----------------------------------------
I would replace the 'rm "${F}"' with 'ls -l "${F}"' until satified with the filters.

We are leveraging the file commands output to determine if the file is a textfile.
The -q option of grep suppresses output. We are only interested in the exit status which is 0 if a pattern match occurs.
If it ain't broke, I can fix that.
Alzhy
Honored Contributor

Re: Need "find" command arguments to seek our ASCII/TEXT files that...

Thanks A. Clay.

I was hoping for a command line wizardry.. i.e Perl.

I do have a script already...
Hakuna Matata.
James R. Ferguson
Acclaimed Contributor

Re: Need "find" command arguments to seek our ASCII/TEXT files that...

Hi Nelson:

# perl -MFile::Find -le 'find(sub{print $File::Find::name if -f $_ && -T $_},@ARGV)' /path

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: Need "find" command arguments to seek our ASCII/TEXT files that...

In that case Perl's -T test (to identify text files) coupled to the File::Find module should be able to handle your needs.
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor
Solution

Re: Need "find" command arguments to seek our ASCII/TEXT files that...

Hi (again) Nelson:

Ooops, sorry, I forgot to add the 30-day criteria to my first offering :-))

# perl -MFile::Find -le 'find(sub{print $File::Find::name if -f $_ && -T _ && -M _ >= 30}, @ARGV)' /path

Regards!

...JRF...

James R. Ferguson
Acclaimed Contributor

Re: Need "find" command arguments to seek our ASCII/TEXT files that...

Hi (once again) Nelson:

I owe you a better job of reading (ECANTREAD)! For the record, here's the inclusion of the size criteria:

# perl -MFile::Find -le 'find(sub{print $File::Find::name if -f $_ && -T _ && -M _ >= 30 && -s >= (5*1024*1024)}, @ARGV)' /path

Regards!

...JRF...
Arturo Galbiati
Esteemed Contributor

Re: Need "find" command arguments to seek our ASCII/TEXT files that...

Hi Nelson,
by ksh:
find . -type f -mtime +30 -size +10240| xargs file|grep "ascii"|cut -d":" -f1

HTH,
Art