Open several PDFs from Terminal

bashcommand linepdfpreviewterminal

I am trying to open all PDFs in a folder from the Terminal.

When I do

open *.pdf

Preview (my default PDF application), opens only one of them.

  • Is there a way to get Preview to open all of them?

  • If not, what other PDF viewer works well for this?

Thanks!

Running Sierra 10.12.6 on a MB Pro.

Best Answer

If you want to just open a list of PDFs all at once, you just need to separate the file names (enclosed with quotes) by a space as follows:

open "file1.pdf" "file2.pdf" ... "fileN.pdf"

This will open every PDF specified on one line.

If you want to open every PDF in a particular directory, use the command (simple for/do loop):

for file in /Path_to_Directory/*.pdf; do open "${file}"; done

Both of the examples above use the default app associated with the file (Preview). If you want to specify a particular app (maybe you have a different PDF viewer but want to use Preview) use the -a flag and specify the app:

for file in /Path_to_Directory/*.pdf; do open -a Preview.app "${file}";  done

Note: Be sure to enclose the variable name in quotes (") to account for spaces and non-printing characters. For example, if you have a file named "My PDF File.pdf", not including the quotes will cause the command to try and open each string ("My", "PDF", and "File") as separate files.