System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Find a word in a directory, never mind uppercase or lowercase

SOLVED
Go to solution
Manuales
Super Advisor

Find a word in a directory, never mind uppercase or lowercase

HI ..
i need to get some paths.
This paths can contain the word:
Archive
ARCHIVE
archive
archivE
aRcChIvE
so, if i run:
find / -mtime +14 -exec ls -l {} \; | awk '{ print $3" "$4" "$6" "$7" "$8" "$NF }' | grep Archive

i only will get paths with a directory name called "Archive" so, how can i do in order to get above word indicated,i need to get them in only one instruction.

i mean,, i need to run command where i say "bring me paths which contain the word Archive never mind if they are uppercase or lowercase"

thansk in advance.

4 REPLIES
Tingli
Esteemed Contributor
Solution

Re: Find a word in a directory, never mind uppercase or lowercase

Put -i after grep, it will ignore the case.
Dennis Handly
Acclaimed Contributor

Re: Find a word in a directory, never mind uppercase or lowercase

If you want performance you could do the name match in find and use "+". Also pass -d to ls:
find / -mtime +14 -name "[Aa][Rr][Cc][Hh][Ii][Vv][Ee]" -exec ls -ld {} + |
awk '{ print $3, $4, $6, $7, $8, $NF }'
James R. Ferguson
Acclaimed Contributor

Re: Find a word in a directory, never mind uppercase or lowercase

Hi:

If you want *performance* you could use Perl's 'find' module:

# perl -MFile::Find -le '@dir=@ARGV?@ARGV:(".");find(sub{print $File::Find::name if m{archive}i && -M $_ > 14},@dir)' /path

You can change to the current directory and run this without any argument to examine it, or you can specify one or more '/path' arguments as above.

Regards!

...JRF...
Manuales
Super Advisor

Re: Find a word in a directory, never mind uppercase or lowercase

Thank you very much all ..!!!! :)