How do I get a list of only the files (not the directories) from a package?
It should be possible with xargs
plus a shell test, for example
dpkg -L elixir | xargs sh -c 'for f; do [ -d "$f" ] || echo "$f"; done'
Simply loop over each line of dpkg -L elixir
and test whether the line is the path of a regular file, then echo
it:
while read f; do [ -f "$f" ] && echo "$f"; done < <(dpkg -L elixir)
Your idea with find
looks good but find
- does not accept stdin and
- searches in the given path while you want to just check properties of the single given path,
so it’s not the right tool here.
With perl oneliner:
dpkg -L elixir | perl -nE 'chomp; say unless -d'
dpkg -L
will list all files/directories in package and output it to stdoutperl -nE
will iterate following perl code over each line ofdpkg
output, leaving current line in default argument variable (called$_
)chomp
removes trailing linefeed from stdin, thus leaving only filename in default argument variable ($_
).say
is short forsay $_
, which will print to stdout default argument if following condition is true.unless -d
(short forunless -d $_
) is condition for previoussay
, and means it will only be true if specified filename is not a directory
So, it will display all filenames which are not directories. If you wanted to display only directories, you would replace unless
with if
. Or if you wanted only symlinks, you could use -l
instead of -d
, etc. (see man perlfunc
for more details)