Operating System - HP-UX
1847256 Members
4197 Online
110263 Solutions
New Discussion

find & ll -t can not work together

 
張育修
New Member

find & ll -t can not work together

Execute find CMD ,Can not list sort files.

find . -mtime -32 -exec ll -t {} \;
-rwxrwx--- 1 root dba 12853 Dec 3 16:26 ./starch.file
-rw-r--r-- 1 root sys 0 Dec 3 16:00 ./vol-percent.txt
-rwxrwx--- 1 oraprod dba 486 Dec 3 16:23 ./arch-input-status.log
-rwxrwx--- 1 oraprod dba 83 Dec 3 16:23 ./arch-sequence.log
-rwxrwx--- 1 root dba 27 Dec 3 16:26 ./arch_cp.file



7 REPLIES 7
Mel Burslan
Honored Contributor

Re: find & ll -t can not work together

when you execute this statement, it will find each individual file and run an "ll -t" command on that file at that instant.

Your expectation from the find command, is, to gather all files to your spec and then run an ll -t on this list. Unfortunately find & exec pair do not work that way.

If you want a chronologically sorted list of files, you need to write a few lines of shell script, using temporary files and whatever else. At this late hour, my brain is not working that nimbly to cobble up something.

________________________________
UNIX because I majored in cryptology...
James R. Ferguson
Acclaimed Contributor

Re: find & ll -t can not work together

Hi:

Mel's interpretation of you problem is correct. When you use the ";" terminator to 'find's '-exec', only *one* argument at a time (here, one file or directory) is passed to the command that is to be executed.

You can cause 'find -exec' to aggregate a very large number of arguments and pass them as a bundle to the command to be run by using a "+" terminator.

If you aren't going to explicitly specify only files to be returned by 'find' like:

# find . -type f -mtime -32 -exec ls -lt {} +

...then use:

# find . -mtime -32 -exec ls -ltd {} +

...which adds the '-d' switch to 'ls' so that you don't duplicate output when 'ls' examines a directory and rescans the files in it that have already been assimilated.

Regards!

...JRF...
Matti_Kurkela
Honored Contributor

Re: find & ll -t can not work together

If you have a very large number of files, even James's solution does not guarantee perfect sorting.

In the "find . -mtime -32 -exec ll -t {} \;" command of the original post, the "find" command produces one "ll -t" command for each file, so the sorting step of the ll command has only 1 file to process each time:

ll -t ./starch.file
ll -t ./vol-percent.txt
etc.

In James's solution, the find command produces one or more command lines like:

ll -t ./starch.file ./vol-percent.txt ...

If the complete list of filenames fits into a single maximum-length command line, the "ll -t" command gets all the files at once and can sort them correctly.

But if the list of filenames is so long that find needs to run two or more command lines, then the files on each command line will be sorted separately. The maximum length of the command line is quite long, but not infinite: see "man 5 limits" for limits ARG_MAX and LINE_MAX. You can use the "getconf" command to view the actual limits on your system.)

This will result in a listing that is made up of multiple "blocks": each block will contain a correctly sorted sub-set, but the time ranges of each block may overlap with other blocks, so the complete list is not guaranteed to be correctly sorted.

MK
MK
Dennis Handly
Acclaimed Contributor

Re: find & ll -t can not work together

>MK: limits ARG_MAX and LINE_MAX.

Only ARG_MAX is important. LINE_MAX is trivially small but does limit xargs(1).

>so the complete list is not guaranteed to be correctly sorted.

Right.
張育修
New Member

Re: find & ll -t can not work together

Thank for your help.
張育修
New Member

Re: find & ll -t can not work together

If you aren't going to explicitly specify only files to be returned by 'find' like:

# find . -type f -mtime -32 -exec ls -lt {} +

...then use:

# find . -mtime -32 -exec ls -ltd {} +

James R. Ferguson
Acclaimed Contributor

Re: find & ll -t can not work together

Hi (again):

> Thank for your help.

If you are satisfied with the answers you received, please read this about assigning points:

http://forums11.itrc.hp.com/service/forums/helptips.do?#28

Regards!

...JRF...