Using dpkg -L <package name>
I am able to obtain a list of all the files from a package, but it contains a list of directories as well, which I want to exclude.
So, for example:
dpkg -L elixir
gives me:
/.
/usr
/usr/bin
/usr/lib
/usr/lib/elixir
/usr/lib/elixir/bin
/usr/lib/elixir/bin/elixir
/usr/lib/elixir/bin/elixirc
/usr/lib/elixir/bin/iex
/usr/lib/elixir/bin/mix
/usr/lib/elixir/lib
/usr/lib/elixir/lib/eex
/usr/lib/elixir/lib/eex/ebin
/usr/lib/elixir/lib/eex/ebin/Elixir.EEx.Compiler.beam
(etc...)
I have tried excluding the directories with the following:
dpkg -L elixir | find -maxdepth 1 -not -type d
But that just gives the file in the current directory.
Piping the dpkg
output to ls
with xargs
also does not seem to allow me to filter out directories.
It should be possible with
xargs
plus a shell test, for exampleSimply loop over each line of
dpkg -L elixir
and test whether the line is the path of a regular file, thenecho
it:Your idea with
find
looks good butfind
so it’s not the right tool here.
With perl oneliner:
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 directorySo, it will display all filenames which are not directories. If you wanted to display only directories, you would replace
unless
withif
. Or if you wanted only symlinks, you could use-l
instead of-d
, etc. (seeman perlfunc
for more details)Another option would be to compare the output of
dpkg
with the results offind
for files: