cancel
Showing results for 
Search instead for 
Did you mean: 

inconsistent find behavior

 
SOLVED
Go to solution
Highlighted
Trusted Contributor

inconsistent find behavior

I am using a script to find large files and give me the long listing or the files found. Doing "find . -size +1000000c" always shows the list of large files found, as expected. If I expand the find command to "find . -size +1000000c -exec ls -l {} \;" - then on some directories it works, but others it lists every file (though with ls -l). What is going on here??
5 REPLIES 5
Highlighted
Acclaimed Contributor
Solution

Re: inconsistent find behavior

Hi Dave:

If you want _files_ only, you need to say-so:

# find . -type f -size +1000000c -exec ls -l {} +

...will perform the 'ls' on the list which consists of FILES only and not files AND DIRECTORIES.

Note, too, that you will gain performance by using the "+' terminator with the '-exec'. THis bundles many arguements together and presents them en mass to 'ls' rather than spawning one 'ls' process for every file found!

Regards!

...JRF...
Highlighted
Honored Contributor

Re: inconsistent find behavior

Dave,

I usually do the same with:

$> find . -size +1000000c | xargs -i ls -ald {}

Of course, that does what James suggested except it uses xargs to handle the "bunching".

James' solution is nicer in that it doesn't require a middle process spawned to handle bunching. Except, that when I'm looking for large things, I also just don't worry about whether its a file or not, because I also want to know about large single directories which exist on the system, which are performance bottlenecks. Yes, I've found directories from programs/programmers with 800,000 files in them... sigh - usually after the programmer wonders why "he can't list" all of the files. He can, put it's painfully slow...

Anyways, another way to do it and incorporate James' cool suggestion (which I didn't know about):

$> find . -size +1000000c -exec ls -al {} +


P.S. Anybody else confused that find -exec doesn't seem to want/need/accept the trailing "\;" anylonger? Or, am I thinking of something else???

We are the people our parents warned us about --Jimmy Buffett
Highlighted
Honored Contributor

Re: inconsistent find behavior

Sorry about the double - post - accidental button push.

BTW, I just realized I didn't explain -the trailing "d" in "ls -ald" tells ls *not* to expand the subdirectories for you.

No points for this post, or the prior mistaken double-post.
We are the people our parents warned us about --Jimmy Buffett
Highlighted
Acclaimed Contributor

Re: inconsistent find behavior

Hi (again):

> TwoProc: Anybody else confused that find -exec doesn't seem to want/need/accept the trailing "\;" anylonger?

When you use the semicolon as a terminator to '-exec's arguments you must escape it with the back-slash to prevent the shell from interpreting it. That is, ";" is special to the shell; the "+" isn't.

Regards!

...JRF...

Highlighted
Honored Contributor

Re: inconsistent find behavior

Wow, I went back and checked, and in my response the last "d" in the "ls -ald" was there. But I see in the posting itself - it isn't! I'm guessing my screen didn't keep up with my backspaces, or I had someother screen junk in there.

Anyway, it's supposed to be:

$> find . -size +10000000c -exec ls -ald +

not

$> find . -size +10000000c -exec ls -al +

...

Geez, I only WISH I could mess up *more* postings today!!! UUUGH!
We are the people our parents warned us about --Jimmy Buffett