...
 
Commits (256)
/* lr - a better recursive ls/find */
Copyright (C) 2015-2019 Leah Neukirchen <purl.org/net/chneukirchen>
Parts of code derived from musl libc, which is
Copyright (C) 2005-2014 Rich Felker, et al.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ALL=lr
ZSHCOMP=_lr
CFLAGS=-g -O2 -Wall -Wno-switch -Wextra -Wwrite-strings
DESTDIR=
PREFIX=/usr/local
BINDIR=$(PREFIX)/bin
MANDIR=$(PREFIX)/share/man
ZSHCOMPDIR=$(PREFIX)/share/zsh/site-functions
all: $(ALL)
clean: FRC
rm -f lr
install: FRC all
mkdir -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(MANDIR)/man1 $(DESTDIR)$(ZSHCOMPDIR)
install -m0755 $(ALL) $(DESTDIR)$(BINDIR)
install -m0644 $(ALL:=.1) $(DESTDIR)$(MANDIR)/man1
install -m0644 $(ZSHCOMP) $(DESTDIR)$(ZSHCOMPDIR)
FRC:
## 1.4.1 (2019-02-08)
* Bugfix release
## 1.4 (2018-04-17)
* Regression: `-Q` was always on, even when not printing to TTY.
## 1.3 (2018-04-05)
* Feature: new option `-P` to quote filenames with `$'...'` syntax.
* Feature: invalid UTF-8 filenames are quoted now.
* Feature: colorized file size output now uses groups of three digits.
* Feature: support $NO_COLOR: http://no-color.org/
## 1.2 (2017-11-17)
* Feature: new option `-B` for breadth first traversal.
* Feature: new syntax `? :` for ternary operator.
* Feature: new action `skip` which is always false.
The common find(1) idiom `-name x -prune -o -print`
is now best written as `name = "x" ? prune && skip : print`.
* Significant speed-up as tsearch is not used anymore.
* Lower memory usage for -U.
* Default widths for -U.
## 1.1 (2017-10-29)
* Feature: lr is substantially faster as files only are stat(2)ed if
the output requires it.
* Feature: new option `-X` to print OSC 8 hyperlinks.
* Feature: new option `-e` for the common case of filtering file names.
* Feature: support for DragonFlyBSD.
* Bug: lr doesn't fail on symlinks refering to themselves anymore.
## 1.0 (2017-08-29)
* **Breaking change**: the `-Q` flag changed meaning to *enable* quoting
(as it does in GNU ls), since shell quoting is not so useful in many
cases using a pipe. Filenames are quoted by default when printing
to TTY.
* Feature: lr now respects the locale, which mainly influences date format.
* Feature: new option `-C` to change the color of files.
* Feature: new action `color <num>` to change the color of files.
* Feature: new argument `@file` to read file names from a file.
* Feature: negated string operations `!=`, `!===`, `!~~`, `!~`, `!=~~`.
* Bug: lr now reports errors and sets exit code when toplevel
arguments can not be stat'ed.
## 0.4 (2017-04-25)
* Feature: argument `-` means read files from standard input
## 0.3.2 (2016-05-20)
* Bug: getopt was called in a wrong way from ARM platforms
## 0.3.1 (2016-03-31)
* Bug: `=~` was not recognized (broken since 0.3)
* Add emacs contrib (lr.el)
## 0.3 (2016-02-28)
* Checking permissions against chmod-style symbolic modes
* `-TA`/`-TC`/`-TM` to select which timestamp to show in `-l`
* Colorize symlink targets
* Show broken links
* On Linux: Display of capabilities, ACL and xattrs in `-l`
* zsh completion
* Some small things in contrib/
This diff is collapsed.
#compdef lr
_lr_format() {
if [[ ${(Q)PREFIX} = *% ]]; then
local -a specs
specs=(
'%:percent sign'
's:file size in bytes'
'S:file size, with human readable unit'
'b:file size in 512-byte blocks'
'k:file size in 1024-byte blocks'
'd:path depth'
'D:device number'
'R:device ID for special files'
'i:inode number'
'I:one space character for every depth level'
'p:full path'
'P:full path without command line argument prefix'
'l:symlink target'
'n:number of hardlinks'
'F:file indicator type'
'f:file basename'
'A:atime prefix'
'C:ctime prefix'
'T:mtime prefix'
'm:octal file permissions'
'M:ls-style symbolic file permissions'
'y:ls-style symbolic file type'
'g:group name'
'G:numeric gid'
'u:user name'
'U:numeric uid'
'e:number of entries in directories'
't:total size used by accepted files'
'Y:file system type'
'x:extended attributes'
)
compset -P "*"
_describe -t lr-format-specifiers 'format specifier' specs -S ''
else
_wanted lr-format-specifiers expl 'format specifier' compadd -S '' %
fi
return 0
}
_lr_order() {
local -a specs
specs=(
'a:atime'
'c:ctime'
'd:path depth'
'e:file extension'
'i:inode number'
'm:mtime'
'n:file name'
'p:directory name'
's:file size'
't:file type'
'v:file name as version number'
'A:atime (reversed)'
'C:ctime (reversed)'
'D:path depth (reversed)'
'E:file extension (reversed)'
'I:inode number (reversed)'
'M:mtime (reversed)'
'N:file name (reversed)'
'P:directory name (reversed)'
'S:file size (reversed)'
'T:file type (reversed)'
'V:file name as version number (reversed)'
)
compset -P "*"
_describe -t lr-order-specifiers 'order specifier' specs -S ''
return 0
}
if (( words[(I)-l] )); then
local timeopt='-T+[show time]:time:((A\:access\ time C\:inode\ change\ time M\:file\ modification\ time))'
fi
_arguments -S : \
'(-F -l -S -f)-0[output filenames NUL-separated]' \
'(-0 -l -S -f)-F[output filenames with type indicator]' \
'(-0 -F -S -f)-l[long output]' \
'(-0 -F -l -f)-S[stat(1)-like output]' \
'(-0 -F -l -S)-f[output with custom format]:format:_lr_format' \
$timeopt \
'(-D)-B[use breadth-first traversal]' \
'(-B)-D[use depth-first traversal]' \
'(-L)-H[only follow symlinks on command line]' \
'(-H)-L[follow all symlinks]' \
'-1[don'\''t go below one level of directories]' \
'-A[don'\''t list files starting with a dot]' \
'-Q[shell quote file names]' \
'-d[don'\''t enter directories]' \
'-G[colorize output]' \
'-X[print OSC 8 hyperlinks]' \
'-h[print human readable size]' \
'-s[strip directory prefix passed on command line]' \
'-x[don'\''t enter other filesystems]' \
'(-o)-U[don'\''t sort results]' \
'(-U)-o[sort order]:order:_lr_order' \
'*-e[only show files where basename matches regexp]:pattern: ' \
'*-t[test expression]:test: ' \
'*-C[colorize path]:path:_files' \
'*:files:_files'
;;; lr.el --- run `lr' and display the results
(define-compilation-mode lr-mode "Lr"
(set (make-local-variable 'compilation-error-regexp-alist)
'(("\\([^ \n']+\\)[*/=>@|]$" 1)
("\\([^ \n']+\\)$" 1)
("'\\(.+\\)'$" 1)))
(set (make-local-variable 'next-error-highlight) nil))
(defun lr (command-args)
"Run lr, with user-specified args, and collect output in a buffer.
While lr runs asynchronously, you can use \\[next-error] (M-x next-error),
or RET in the *lr* buffer, to go to the files lr found."
(interactive (list (read-shell-command "Run lr (like this): "
"lr " 'lr-history)))
(compilation-start command-args 'lr-mode))
(provide 'lr)
;;; lr.el ends here
" :Lr <lr-args> to browse lr(1) results in a new window,
" press return to open file in new window.
command! -n=* -complete=file Lr silent exe "R" "lr" <q-args> | res | silent f [lr] | map <buffer><CR> $hgF
#!/bin/sh
# lrls - lr with GNU ls style output
color=
[ -t 1 ] && color=-GG
lr $color -A1s -t '!type == d || depth > 0' "$@" |git column --mode=dense --pad=2
#!/bin/sh
# lrocate [PATTERN] [LR OPTIONS...] - call lr(1) on locate(1) results
pattern=$1; shift
locate -0 "$pattern" | xe -0 -N0 lr -lG "$@"
lr (1.4.1-1) unstable; urgency=medium
* New upstream release (2019-02-08)
* Make gbp commit (compressed) upstream tarballs.
This avoids cases where the orig tarball is not generated reproducibly.
* debian/control
+ Update maintainer's email address
+ Declare compliance with policy v4.3.0.
No change required
+ Switch to debhelper 12.
The dh compatibility level is now set by a build-depends.
-- Nicolas Braud-Santoni <nicoo@debian.org> Sat, 09 Feb 2019 15:52:47 +0100
lr (1.4-1) unstable; urgency=medium
* New upstream version (2018-04-17)
* debian/control
- Move the packaging repository to salsa.d.o
- Declare compliance with policy version 4.1.4.
No change required.
* debian/rules: Drop redundant dh argument
-- Nicolas Braud-Santoni <nicolas@braud-santoni.eu> Mon, 30 Apr 2018 14:26:55 +0200
lr (1.2-1) unstable; urgency=medium
* New upstream version (2017-11-17)
* Performance improvements
* `-U` now supports default width
* New features
* -B option for breadth-first search
* New ternary `?:` operator
* New `skip` action
-- Nicolas Braud-Santoni <nicolas@braud-santoni.eu> Thu, 23 Nov 2017 13:16:22 +0100
lr (1.1-2) unstable; urgency=medium
* Fix build on hurd (Closes: #880852)
-- Nicolas Braud-Santoni <nicolas@braud-santoni.eu> Sat, 11 Nov 2017 23:44:19 +0100
lr (1.1-1) unstable; urgency=medium
* Initial packaging (Closes: #861792)
-- Nicolas Braud-Santoni <nicolas@braud-santoni.eu> Mon, 30 Oct 2017 18:29:10 +0100
Source: lr
Maintainer: Nicolas Braud-Santoni <nicoo@debian.org>
Section: utils
Priority: optional
Build-Depends: debhelper-compat (= 12)
Standards-Version: 4.3.0
Homepage: https://github.com/leahneukirchen/lr
Vcs-Browser: https://salsa.debian.org/debian/lr
Vcs-Git: https://salsa.debian.org/debian/lr.git
Package: lr
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: list files, recursively
lr is a tool for generating file listings,
which includes the best features of ls(1), find(1), stat(1) and du(1).
.
It has a powerful and user-friendly filter syntax,
sorting and formatting capabilities.
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: lr
Source: https://github.com/leahneukirchen/lr
Files: *
Copyright: Copyright (c) 2015-2017 Leah Neukirchen <leah@vuxu.org>
License: MIT
Files: lr.c
Copyright: Copyright (c) 2015-2017 Leah Neukirchen <leah@vuxu.org>
Copyright (C) 2005-2014 Rich Felker, et al.
License: MIT
Files: debian/*
Copyright: Copyright (c) 2017 Nicolas Braud-Santoni <nicolas@braud-santoni.eu>
License: MIT
License: MIT
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
.
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[DEFAULT]
upstream-tag = v%(version)s
[buildpackage]
pristine-tar-commit = True
compression = xz
#!/usr/bin/make -f
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
%:
dh $@
override_dh_auto_install:
dh_auto_install -- PREFIX=/usr
# Upstream releases signed Git tags, rather than signed tarballs
lr source: debian-watch-may-check-gpg-signature
version=3
opts=filenamemangle=s/.+\/v?(\d\S+)\.tar\.gz/lr-$1\.tar\.gz/ \
https://github.com/chneukirchen/lr/releases .*/v?(\d\S+)\.tar\.gz
\ No newline at end of file
.Dd July 27, 2017
.Dt LR 1
.Os
.Sh NAME
.Nm lr
.Nd list files, recursively
.Sh SYNOPSIS
.Nm
.Op Fl 0 | Fl F | Fl l Oo Fl TA | Fl TC | Fl TM Oc | Fl S | Fl f Ar fmt
.br
.Op Fl B | Fl D
.Op Fl H | Fl L
.Op Fl 1AGPQXdhsx
.Op Fl U | Fl o Ar ord
.br
.Op Fl e Ar regex
.Op Fl t Ar test
.Op Fl C Oo Ar color Ns Li \&: Oc Ns Ar path
.Ar path\ ...
.Sh DESCRIPTION
.Nm
is a versatile tool to generate file listings with configurable
formatting, ordering and filtering.
.Pp
When no
.Ar path
is given or
.Ar path
is an empty string, the current directory is used by default.
.Pp
The special
.Ar path
argument
.Sq Ic \&\-
makes
.Nm
read file names from standard input,
instead of traversing
.Ar path .
Likewise, the special
.Ar path
argument
.Ic \&@ Ns Ar file
makes
.Nm
read file names from
.Ar file .
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl 0
Output filenames separated by NUL bytes.
Likewise, read input filenames separated by NUL bytes.
.It Fl F
Output filenames and an indicator of their file type (one of
.Sq Li */=>@| ) .
.It Fl l
Long output a la
.Sq Ic ls -l
(implies
.Fl Q ) .
.It Fl TA
With
.Fl l ,
print atime.
.It Fl TC
With
.Fl l ,
print ctime.
.It Fl TM
With
.Fl l ,
print mtime.
This is the default.
.It Fl S
Output inspired by
BSD
.Xr stat 1
(implies
.Fl Q ) .
.It Fl f Ar fmt
Custom formatting, see
.Sx FORMATTING .
.It Fl B
Use breadth first traversal.
For each depth of the directory tree,
files are sorted and printed,
then the next depth is looked at.
.It Fl D
Use depth first traversal.
.Ic prune
will not work, but
.Ic entries
and
.Ic total
are computed on the fly.
.It Fl H
Only follow symlinks on command line (default: don't follow symlinks).
.It Fl L
Follow all symlinks.
.It Fl 1
Don't go below one level of directories.
.It Fl A
Don't list files starting with a dot.
.It Fl P
Quote file names using
Austin Group #249 syntax
.Li \&$' Ns No ... Ns Li \&'
(implies
.Fl Q ) .
.It Fl Q
Quote file names (default for output to TTY).
.It Fl d
Don't enter directories.
.It Fl G
Colorize output to TTY.
Use twice to force colorized output.
If the environment variable
.Ev NO_COLOR
is set, colors are never used.
.It Fl X
Output OSC 8 hyperlinks to TTY.
Use twice to force hyperlinks.
.It Fl h
Print human readable size for
.Fl l
(also
.Ic %s ) .
.It Fl s
Strip directory prefix passed on command line.
.It Fl x
Don't enter other filesystems.
.It Fl U
Don't sort results.
.It Fl o Ar ord
Sort according to
.Ar ord ,
see
.Sx SORT ORDER .
.It Fl e Ar regex
Only show files where basename matches the POSIX ERE
.Ar regex .
.It Fl t Ar test
Only show files matching the expression
.Ar test ,
see
.Sx TESTS .
Multiple occurrences of
.Fl t
and
.Fl e
are regarded as a conjunction.
.It Fl C Oo Ar color Ns Li \&: Oc Ns Ar path
Behaves as if
.Ar path
was passed like an ordinary argument,
but overrides the color of the file names to the number
.Ar color
which must be between 0 and 255 (default: 2, green).
.Pp
Implies
.Fl GG .
.El
.Sh FORMATTING
.Nm
format strings support the following escape sequences:
.Pp
.Bl -tag -compact -width Ds
.It Ic \ea , \eb , \ef , \en , \er , \ev
Special characters as in C.
.It Ic \e Ns Ar ddd
Byte with one, two or three-digit octal value.
.It Ic \ex Ns Ar dd
Byte with one or two-digit hexadecimal value.
.It Ic \&%%
A plain
.Sq % .
.It Ic \&%s
File size in bytes
.It Ic \&%S
File size, with human readable unit
.It Ic \&%b
File size in 512-byte blocks
.It Ic \&%k
File size in 1024-byte blocks
.It Ic \&%d
Path depth
.It Ic \&%D
Device number
.Va ( stat.st_dev )
.It Ic \&%R
Device ID for special files
.Va ( stat.st_rdev )
.It Ic \&%i
Inode number
.It Ic \&%I
One space character for every depth level
.It Ic \&%p
Full path
.Ic ( \&%P
if
.Fl s
is used)
.It Ic \&%P
Full path without command line argument prefix
.It Ic \&%l
Symlink target
.It Ic \&%n
Number of hardlinks
.It Ic \&%F
File indicator type symbol (one of
.Sq Li */=>@| )
.It Ic \&%f
File basename (everything after last
.Li / )
.It Ic \&%A- , %C- , %T-
relative age for atime/ctime/mtime.
.It Ic \&%A Ns Ar x , Ic \&%C Ns Ar x , Ic \&%T Ns Ar x
result of
.Xr strftime 3
for
.Ic \&% Ns Ar x
on atime/ctime/mtime
.It Ic \&%m
Octal file permissions
.It Ic \&%M
ls-style symbolic file permissions
.It Ic \&%y
ls-style symbolic file type
.Sq ( Li bcdfls )
.It Ic \&%g
Group name
.It Ic \&%G
Numeric gid
.It Ic \&%u
User name
.It Ic \&%U
Numeric uid
.It Ic \&%e
Number of entries in directories
.It Ic \&%t
Total size used by accepted files in directories (only with
.Fl D )
.It Ic \&%Y
Type of the filesystem the file resides on
.It Ic \&%x
Linux-only:
Print a combination of
.Sq Li \&#
for files with security capabilities,
.Sq Li \&+
for files with an ACL,
.Sq Li \&@
for files with other extended attributes.
.El
.Sh SORT ORDER
Sort order is string consisting of the following letters.
Uppercase letters reverse sorting.
Default sort order is
.Sq Ic n .
.Pp
.Bl -tag -compact -width Ds
.It Ic a
atime
.It Ic c
ctime
.It Ic d
path depth
.It Ic e
file extension
.It Ic i
inode number
.It Ic m
mtime
.It Ic n
file name
.It Ic p
directory name
.It Ic s
file size
.It Ic t
file type.
This sorts all directories before other files.
.It Ic v
File name as version numbers (sorts
.Sq 2
before
.Sq 10 ) .
.El
.Pp
E.g.\&
.Sq Ic Sn
sorts first by size, smallest last, and then by name
(in case sizes are equal).
.Sh TESTS
.Nm
tests are given by the following EBNF:
.Bd -literal
<expr> ::= <expr> || <expr> -- disjunction
| <expr> && <expr> -- conjunction
| <expr> ? <expr> : <expr> -- ternary operator
| ! <expr> -- negation
| ( <expr )
| <timeprop> <numop> <dur>
| <numprop> <numop> <num>
| <strprop> <strop> <str>
| <typetest>
| <modetest>
| prune -- do not traverse into subdirectories
| print -- always true value
| skip -- always false value
| color <num> -- always true value, override 256-color
<timeprop> ::= atime | ctime | mtime
<numprop> ::= depth | dev | entries | gid | inode
| links | mode | rdev | size | total | uid
<numop> ::= <= | < | >= | > | == | = | !=
<dur> ::= "./path" -- mtime of relative path
| "/path" -- mtime of absolute path
| "YYYY-MM-DD HH:MM:SS"
| "YYYY-MM-DD" -- at midnight
| "HH:MM:SS" -- today
| "HH:MM" -- today
| "-[0-9]+d" -- n days ago at midnight
| "-[0-9]+h" -- n hours before now
| "-[0-9]+m" -- n minutes before now
| "-[0-9]+s" -- n seconds before now
| [0-9]+ -- absolute epoch time
<num> ::= [0-9]+ ( c -- *1
| b -- *512
| k -- *1024
| M -- *1024*1024
| G -- *1024*1024*1024
| T )? -- *1024*1024*1024*1024
<strprop> ::= fstype | group | name | path | target | user | xattr
<strop> ::= == | = | != -- string (in)equality
| === | !=== -- case insensitive string (in)equality
| ~~ | !~~ -- glob (fnmatch)
| ~~~ | !~~~ -- case insensitive glob (fnmatch)
| =~ | !=~ | !~ -- POSIX Extended Regular Expressions
| =~~ | !=~~ -- case insensitive POSIX Extended Regular Expressions
<str> ::= " ([^"] | "")+ " -- use "" for a single " inside "
| $[A-Za-z0-9_]+ -- environment variable
<typetest> ::= type ( == | = | != ) ( b | c | d | p | f | l )
<modetest> ::= mode ( == | = -- exact permissions
| & -- check if all bits of <octal> set
| | -- check if any bit of <octal> set
) <octal>
| mode = "<chmod>" -- check if symbolic mode is satisfied
<octal> ::= [0-7]+
<chmod> ::= <clause> (, <clause>)+
<clause> ::= [guoa]* [+-=] [rwxXstugo]* -- see chmod(1)
.Ed
.Sh EXIT STATUS
.Ex -std
.Sh SEE ALSO
.Xr du 1 ,
.Xr find 1 ,
.Xr ls 1 ,
.Xr stat 1 ,
.Xr tw 1
.Sh AUTHORS
.An Leah Neukirchen Aq Mt leah@vuxu.org
.Sh LICENSE
.Nm
is licensed under the terms of the MIT license.
This diff is collapsed.
lr.png

11.7 KB