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:


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.

4 Answers 4


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

  1. does not accept stdin and
  2. 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.


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'

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 stdout
  • perl -nE will iterate following perl code over each line of dpkg 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 for say $_, which will print to stdout default argument if following condition is true.
  • unless -d (short for unless -d $_) is condition for previous say, 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)

  • 1
    This is my new favorite :) May 30, 2019 at 16:57
  • I really like this. May 31, 2019 at 5:12

Another option would be to compare the output of dpkg with the results of find for files:

comm -12 \
   <(dpkg -L kate | sort ) \
   <(find $( dpkg -L kate ) -maxdepth 1 -type f | sort )

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .