How to Use the macOS qlmanage Command to Preview Files in the Terminal

The Graphical Disconnect in the Terminal

The command line is unmatched for speed and automation when handling text files, moving directories, or altering system configurations. However, it suffers from a significant limitation: it is inherently text-based.

If you are organizing a folder full of images, PDFs, or video files in the macOS Terminal, you frequently encounter a problem. You might see a file named IMG_4921.jpg or document_final_v2.pdf, but you have no idea what those files actually contain.

Normally, you would have to leave the terminal, open Finder, locate the directory, and double-click the file to open it in Preview or use the Quick Look spacebar shortcut. This constant switching between the terminal and the graphical interface breaks your workflow.

macOS solves this with a hidden command-line bridge called qlmanage. This command allows you to trigger the graphical Quick Look window directly from the terminal, instantly previewing the file without launching a full application.

Step 1: The Basic Preview Command

Open the Terminal application (located in Applications > Utilities).

The qlmanage tool is a debugging utility for the Quick Look Server, but it has a specific flag (-p for Preview) that we can use to view files.

Navigate to a folder containing an image or a PDF. For example:

cd ~/Desktop

To preview a file named photo.jpg, type:

qlmanage -p photo.jpg

Press Enter. The standard, semi-transparent macOS Quick Look window will instantly pop up on your screen, displaying the image.

(Note: Because it is a debugging tool, it will print some diagnostic text into your terminal. You can safely ignore this output.)

Step 2: Closing the Preview

When you trigger Quick Look via the terminal, the terminal session is temporarily paused while the preview window is open.

To close the preview and return control to the terminal, you can either:

  1. Click the small “X” in the corner of the Quick Look window.
  2. Press the Spacebar (if the Quick Look window is the active application).
  3. Press Ctrl + C in the terminal window to terminate the preview process.

Step 3: Previewing Multiple Files

You are not limited to previewing one file at a time. You can pass multiple file names to the command.

qlmanage -p photo1.jpg photo2.png report.pdf

When the Quick Look window opens, it will display the first file. Because you passed multiple files, the Quick Look window will include the standard navigation arrows at the top, allowing you to click through the different files just as you would in the Finder.

Step 4: Silencing the Debug Output

As mentioned earlier, qlmanage prints messy diagnostic information to the terminal (e.g., Testing Quick Look preview with files...). If you use this command frequently, this output clutters your screen.

You can use standard Linux redirection to send that diagnostic output into the void (/dev/null), keeping your terminal clean.

qlmanage -p photo.jpg &> /dev/null

This command opens the preview window silently, returning no text to the terminal.

Step 5: Creating a Custom Alias (Optional but Recommended)

Typing qlmanage -p filename &> /dev/null every time you want to preview a file is tedious. You can make this feature much more useful by creating a custom, shorter alias in your shell configuration file (like .zshrc).

You can map the command to a simple word like preview or ql.

If you add the following line to your ~/.zshrc file:

alias ql="qlmanage -p "$@" &> /dev/null"

You can then reload your terminal and simply type:

ql photo.jpg

This provides a seamless, lightning-fast way to view the contents of graphical files without ever touching the mouse or leaving the command line.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.