[ale] Bash script

Bob Toxen transam at verysecurelinux.com
Sat Apr 12 21:57:09 EDT 2025


Y'all might want to test your code before offering it as a solution or
note it as untested.

On a *nix file system, files that are stored in a directory inode are
NOT sorted.  Thus, the "ls -lta {}" that is executed on each non-sorted
entry will NOT be a list sorted by time.  Oh, that is after you figure out that
you need a trailing \; to terminate the -exec operator.

The following seems to work for me but may fail if any files are larger
than 999999999 bytes:

  ls -l --full-time | sort -k 6 | head -3 |tail -1
  ls -l --full-time | sort -k 6 |  tail -1

Enjoy,
Bob

On Sat, Apr 12, 2025 at 06:58:19PM -0400, dj-Pfulio via Ale wrote:
> The answer is stdout versus standard error. 
> 
> On April 12, 2025 6:26:32 PM EDT, Ron via Ale <ale at ale.org> wrote:
> >Boris Borisov via Ale wrote on 2025-04-12 14:42:
> >
> >> I'm trying to list all files on SSD disk (Windows) and to find the oldest file and the newest file.
> >
> >Here's something that can be get the newest and oldest files - further tweaking should be able to craft it into a single command:
> >
> >
> >## Newest:
> >find $mount_point -type f -exec ls -lta {} \+  | head -n 1
> >
> >## Oldest:
> >find $mount_point -type f -exec ls -lta {} \+  | tail -n 1
> >
> >
> >Bonus points to anyone who can explain why the `head` results include the one file plus this:
> >
> >> find: ???ls??? terminated by signal 13


More information about the Ale mailing list