Skip to content

Commit

Permalink
lsx.mtime: don't default to listing current dir with time-delta spec
Browse files Browse the repository at this point in the history
  • Loading branch information
mk-fg committed Oct 27, 2024
1 parent a747c2c commit 99ebfe8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -461,14 +461,21 @@ ways that are occasionally useful. All those are available via various options -
see `-h/--help` for a full list of those.

For example, to print `-a/--adjacent` files (w/ some ordering):

``` console
% lsx -aS data/chunk-12345.bin # default up to 10 before/after, w/ S=size ordering
% lsx -a 50as data/chunk-13.bin # only 50 files larger than specified one
% lsx -a 5bt myapp/state.log # up to 5 logs right before state.log by mtime
% lsx -fa a3 logs/20230515.log # 3 log-files (-f/--files) with names after that one
```

Or files within `-t/--mtime` vicinity/ranges:
``` console
% lsx -t 1h cache/a/bcdefg.json # files created/changed within 1h of that one
% lsx -t 5d/10d cache/*/* # mtime in 5d-10d ago range
% lsx -rt 2024-10-20/2024-10-25 # between those dates in the current dir
% lsx -rt 1am/3:30 logs # logs changed from 1am to 3:30am earlier today
```

Simple python script with no extra dependencies.

<a name=hdr-trunc-filenames></a>
Expand Down
6 changes: 4 additions & 2 deletions lsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def main(argv=None):
If delta (relative time) is specified, files/dirs within that vicinity from
other file/dir command-line arguments are listed (and at least one is required).
If time range is specified (two absolute or relative timestamps in any order),
then either files/dirs that have mtime within that range are listed, either in the
then files/dirs that have mtime within that range are listed, either in the
current dir, or among/within specified file/dir arguments (see -r/--recursive option).
Multiple time ranges can be specified.
Results are ordered by mtime, pipe through "sort" for alphabetic ordering.
Expand All @@ -254,11 +254,13 @@ def main(argv=None):

if opts.mtime:
no_opts, td = False, mtime_parse(opts.mtime, parser.error)
if opts.recursive and not paths: paths = [pl.Path('.')]
if td.vicinity:
if not paths: parser.error(
'At least one path argument required for -t/--mtime time-delta' )
for p in mtime_list(paths, td): _pp(p)
else:
ps = list()
if opts.recursive and not paths: paths = [pl.Path('.')]
for p in paths:
if not p.exists(): p_err(f'path inaccessible [ {p} ]'); continue
if opts.recursive and p.is_dir(): ps.extend(p.iterdir())
Expand Down

0 comments on commit 99ebfe8

Please sign in to comment.