Hi,
I'd like to sort regular files by modification time that resides in directory tree.
Is this command correct?
find /path/to/dir -type f | xargs ls -ltr
I disagree, that is the correct command to do this, the only problem however is that if there are enough files to require multiple ls -ltr commands, each of those will be sorted individually.
I was thinking of something like a combination of these two commands to get around that...
[tt]# files older than 6 months
find . -type f | xargs ls -l | awk '!($8 ~ /:/)' | sort -k 8,8n -k 6,6M -k 7,7n > /tmp/sorted
# files newer than 6 months
find . -type f | xargs ls -l | awk '$8 ~ /:/' | sort -k 6,6M -k 7,7n -k 8,8n >> /tmp/sorted[/tt]
... the only problem being that if it was February, for example, you would still have files from the previous year listed with timestamps and they would be sorted incorrectly by the previous command, so it gets complicated...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.