I want to display latest files (created or modified) recursively in a path.
I tried in different ways, but didn't get any desired output:
find $path -type f -exec ls -lt {} \; | sort -n -r
find $path -type f -printf %p";" | xargs -d ";" ls -t
Second one is giving the error:
xargs: The -d flag is not valid.
Usage: xargs [-p][-t] [-e[EndOfFileString]] [-E EndOfFileString]
[-I ReplacementString] [-i[ReplacementString]] [-L Number]
[-l[Number]] [-n Number [-x]] [-s Size] [Command [Argument ...]]
find: 0652-017 -printf is not a valid option.
Any other way to display the latest files recursively ?
Just like most people seeking help, you neglected to specify your operating system. Without that information we are forced to guess or we must limit ourselves to a less functional common denominator.
Your first post suggests you are not using a GNU/Linux system, otherwise -printf would have been recognized. Had it been supported, it could have accomplished the decoration in a decorate-sort-dedecorate solution:
Since that doesn't seem possible, we have to turn elsewhere. Many systems have a stat tool (or something similar) which can output numerically sortable timestamp data, but these utilities are highly unportable. With the proper options, such a tool could be invoked effectively by find's -exec.
I am running it on bash and as earlier mentioned in my previous post, ls format is month, date and time for columns 6,7 & 8 respectively. i have tried that and it works fine thats why i've suggested this...
May be for other format we need to modify it lit bit..
"locale dependent" means "what works for you won't work for someone else". Even worse, it will fail in ways that aren't obvious -- the output will be scrambled or wrong, rather than getting an error message or "option not supported".
It's better to write code that works in many places than make someone else fix code that doesn't.
As what you said "locale dependent". Okies.. that's fine. agreed..
But I'll try as per what resources I have. This is not possible to check for all other types if I don't have it.
"Locale dependent" means "what works for you won't work for someone else". Even worse, it will fail in ways that aren't obvious -- the output will be scrambled or wrong, rather than getting an error message or "option not supported". ls' output on even the same machine can be different for different files. For new files, my version of ls shows dates; for older ones, it shows only years. You can't sort that.
Using find -prinf means you always get exactly what you ask for, no more, no less.
Yes. agreed...
but till the time you don't know what is result of the command we can't comment anything. max we can request user to give proper inputs but this never happens.
as i am not master you do expect post like this.
ps: i m not fighting over which method is good...