Operating System - HP-UX
1752846 Members
3577 Online
108789 Solutions
New Discussion юеВ

Find command - directory & file selection

 
SOLVED
Go to solution
Kevin McKie
Occasional Advisor

Find command - directory & file selection

Hi, folks.

I have an archive directory containing several subdirectories, one of which is called "secure". I need to compress all files in all the subdirs (using compress -f or compressdir -f) EXCEPT the files in "secure" - they may be needed at an instant's notice. Your help would be much appreciated.
Si monumentum requiris, ecce Washington.
15 REPLIES 15
Peter Kloetgen
Esteemed Contributor

Re: Find command - directory & file selection

Hi Kevin,

the following command should do it for you:

find /path/to/directory -type d -print | grep -v 'secure' | compressdir -f

Allways stay on the bright side of life!

Peter
I'm learning here as well as helping
Kevin McKie
Occasional Advisor

Re: Find command - directory & file selection

Thanks, Peter.

That worked OK as it stood, but then I started experimenting. I tried to identify a single directory for compression using:

find . -type d | grep pioneer | compressdir -f

(where pioneer is another of the sub-dirs) and every single sub-dir in the archive directory was compressed; the grep seems to have been ignored.

My original intention was to include in a log a count of the files to be compressed (i.e. everything not ending in .Z), which I did with:

UnCompFiles=$(find . -type f -name "*[!Z]" -print | wc -l)

Unfortunately, that includes the files in the secure sub-dir. If possible, I'd like to know how to find uncompressed files in all archive sub-dirs except the secure sub-dir. A pint of warm, flat British beer to the first correct answer!
Si monumentum requiris, ecce Washington.
Kevin McKie
Occasional Advisor

Re: Find command - directory & file selection

Hi, Peter et al. -

Scratch part of my last message - I missed out the "-print" from my find. It now identifies the pioneer directory accurately, but compressdir -f doesn't work properly; it doesn't compress empty files, a requirement of mine.

So it now looks as though my definitive question is: how do I identify uncompressed files in sub-dirs other than secure so that I can compress them using compress -f?

Thanks again,

Kevin
Si monumentum requiris, ecce Washington.
Peter Kloetgen
Esteemed Contributor

Re: Find command - directory & file selection

Hi again Kevin,

you want to know the number of all files which where compressed, but no files to be compressed which are under subdirectory secure?

Here we go.....

var=`find /path -type d -print | grep -v 'secure' | ls -Al | wc -l`

That should do it for you....

Allways stay on the bright side of life!

Peter
I'm learning here as well as helping
Steve Steel
Honored Contributor

Re: Find command - directory & file selection

Hi

UnCompFiles=$(find . -type f -name "*[!Z]" -print |grep -v /secure/| wc -l)

Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Peter Kloetgen
Esteemed Contributor

Re: Find command - directory & file selection

Hi the third time Kevin,

sorry for my last posting, there is a little error in it:

ls -Al --> output are "allmost" all entries, without "." and "..", but also a header line, named "total" and then the number of blocks of directory. Either you forget the -l option or you include the command "grep -v total" before the command "wc -l"

Allways stay on the bright side of life!

Peter
I'm learning here as well as helping
Kevin McKie
Occasional Advisor

Re: Find command - directory & file selection

Hi, Peter & Steve -

You've both been incredibly helpful, so thank you for your kind patience. Warm British beers all round!

Your answers to stripping out the "secure" sub-dir both involve piping find's output to grep; what I'm really trying to get to here is how to use *only* the find command. That way, I can use the -exec primary to call compress -f as mentioned in an earlier posting. I've been experimenting with the -path, -prune and -only primaries but haven't been successful.

A juicy 10 points to whoever shows me how to read the sub-dirs as I'd like, using only find's primaries :-)

Honest - this'll be my last question for a while!
Si monumentum requiris, ecce Washington.
Darren Prior
Honored Contributor

Re: Find command - directory & file selection

Hi Kevin,

You may wish to leave off the compressdir -f whilst you're experimenting so you can just see the list of directories that will be passed to compressdir.

To answer your query about counting the files, you need to filter out any files which have 'secure' in the returned path. I'd suggest changing your line to:

UnCompFiles=$(find . -type f
-name "*[!Z]" -print | grep -v 'secure' | wc -l)
If an individual file is likely to contain the word secure then it might be better to include the trailing slash after secure in the grep statement.

regards,

Darren.
Calm down. It's only ones and zeros...
H.Merijn Brand (procura
Honored Contributor

Re: Find command - directory & file selection

Also study 'man xargs', which might prove useful in your quest

just another ??? 0.02
Enjoy, Have FUN! H.Merijn