In the zsh
shell, the four most recently modified regular files in the current directory can be had by the globbing pattern
./*(.Dom[1,4])
... where ./*
matches all names in the current directory and the parenthesis modifies the behavior of the matching. The .
makes the *
match only regular files while D
makes it also match hidden names (as with the dotglob
shell option enabled in the bash
shell). The om
orders the resulting list of names by modification timestamp and the [1,4]
picks out the first four names.
To call tail
on these files:
tail ./*(.Dom[1,4])
From the bash
shell:
zsh -c 'tail ./*(.Dom[1,4])'
If you want consider all files in the current directory or anywhere below it, then use
zsh -c 'tail ./**/*(.Dom[1,4])'
The **
pattern works in a similar manner to the same globbing pattern in bash
when the globstar
shell option is enabled, i.e. it matches down into subdirectories recursively. The D
in the glob qualifier would make the **
match into subdirectories with hidden names.
ls
is a bad idea. So I should probably think about a better approach – Morpheus Nov 30 '20 at 08:24