Your Search Bar For Shrewd Tips

How To Close Xdg Open


If you searched for how to close xdg-open, you may be expecting it to behave like a separate application. Usually, it does not. The Linux command xdg-open asks your desktop environment to open a file, folder, or web address with the application associated with it. After handing off the request, xdg-open often exits, while the browser, document viewer, or file manager remains open.

To close what xdg-open opened, close the application or window that received the request. If a process is actually stuck, you can identify it and stop it from the terminal. This guide explains both approaches, how to close an app opened by xdg-open, and what to do when the command appears to keep running.

What Does xdg-open Do?

xdg-open is a command-line utility used on many Linux desktops. It opens a URL or local file using the system’s default application. For example, it might send a website address to your default browser or a PDF to your document viewer.

xdg-open https://example.com
xdg-open ~/Documents/report.pdf
xdg-open ~/Downloads

The command is generally a launcher, not the application itself. It may pass your request to a desktop service, another helper program, or the chosen application. As a result, the process you see in the terminal may finish quickly even though the browser or file viewer stays open.

There is no standard xdg-open close command. Closing the opened window is normally the right solution; stopping xdg-open itself is only useful if its process is still running and causing a problem.

How To Close an App Opened by xdg-open

For most users, the simplest way to close the result of an xdg-open command is to close its application normally. This avoids interrupting unrelated processes or losing unsaved work.

  • Browser: Close the tab or browser window that opened the URL. If you want to close the entire browser, use its normal Quit or Exit option.
  • Document viewer: Close the PDF or document window using its close button or the application’s File menu.
  • File manager: Close the window that opened the requested folder.
  • Other application: Save any changes first, then exit the program in the usual way.

You can also use the common keyboard shortcut Alt+F4 to close the focused window in many Linux desktop environments. On macOS-style keyboard layouts or customized desktops, the shortcut may differ. Check your desktop’s keyboard settings if it does not work.

Remember that xdg-open may open a new tab in an existing browser window rather than creating a new window. In that case, close the specific tab if you only want to dismiss the page, or quit the browser if you intend to close everything.

How To Stop xdg-open From the Terminal

If the terminal has not returned to the prompt, or you can see that an xdg-open process is still active, you can inspect and stop that process. First, list processes whose command line includes xdg-open:

pgrep -af xdg-open

The output may show a process ID (PID) and command. If a relevant process appears, send it a normal termination signal with kill, replacing PID with the actual number:

kill PID

For example, if the process ID shown is 2468, run:

kill 2468

This requests a graceful shutdown. Give the process a moment to exit, then check again with pgrep -af xdg-open. Avoid using a guessed process ID; confirm the command and process first so you do not stop the wrong program.

If you started xdg-open directly in the current terminal and it is still running in the foreground, press Ctrl+C to interrupt that command. This stops the foreground job in that terminal. It does not necessarily close the browser or other application that received the request.

Why Killing xdg-open May Not Close the Window

Stopping xdg-open is not the same as closing the program it opened. In many setups, the command sends a request to a browser or desktop service and then exits. The browser is a separate process, so terminating the launcher will not close the browser window or remove the opened tab.

The reverse can happen, too: a desktop helper may remain active even after the visible window closes. That does not automatically mean anything is wrong. Background processes are common in Linux desktops, and they may handle requests, provide integration, or keep an application ready for reuse.

For this reason, do not use broad commands such as killall or pkill -f just because you want to close one page or file. A broad pattern can match more than the launcher, including a browser or another unrelated command. Close the specific window first, and only stop a process after checking what it is.

How To Find the Application xdg-open Started

If you do not know which application received the request, inspect the open windows or check running processes. Many desktop environments have a window overview or task switcher that shows open applications. You can also search the process list for likely application names.

ps -ef | less

Press / in less and type a term such as firefox, chromium, evince, or the name of your preferred application. Press n to move to the next match, and press q to exit.

Another option is to check which application is configured as the default for a file type. The following command prints the default handler for PDF files on many systems:

xdg-mime query default application/pdf

For a web link, the default browser may be configured through your desktop’s settings, a MIME association, or a portal service. The exact method varies by distribution and desktop environment. Identifying the handler can help you find the right window to close, but changing the default application is not necessary just to close it.

What To Do If xdg-open Is Stuck

If the command has been running for an unusually long time, start with basic checks. Confirm that the target application has not displayed a confirmation dialog behind another window. Check whether the desktop is responsive, whether the requested file exists, and whether the application can open the file when launched directly.

  • Check for a hidden prompt: Look through open windows for a first-run notice, file permission prompt, or application error.
  • Verify the target: For a local file, check that its path is correct and that you have permission to read it.
  • Test the handler: Open the same file or URL from the relevant application or file manager.
  • Inspect the process: Use pgrep -af xdg-open to see whether the launcher is still active.
  • Stop only the confirmed process: If it is genuinely stuck, use kill PID and recheck its status.

If a normal termination request does not work, a forced signal is available as a last resort:

kill -KILL PID

Use SIGKILL sparingly. It does not give the process a chance to clean up, and it is rarely needed for a short-lived launcher. It may also leave the application that was meant to open the file untouched. If the actual browser or viewer is frozen, identify that application’s PID separately and consider whether unsaved work could be lost before terminating it.

How To Close a Background or Suspended Job

If you launched the command from a shell and placed it in the background with &, the shell may report a job number. You can list the current shell’s jobs with:

jobs -l

To request that a particular job stop, use its job number. For example, if the shell lists job 1, run:

kill %1

The jobs command only shows jobs belonging to that current shell. It will not list every process running on your desktop, and it will not necessarily show the browser or file manager that received the request. If you closed the terminal or opened the application from a file manager, use the desktop window controls or inspect system processes instead.

Preventing the Wrong Application From Opening

Sometimes the real issue is not how to close xdg-open, but that it opened the wrong application. You can change the default handler through your desktop’s settings, often in a section called Default Applications, Preferred Applications, or File Associations. The wording depends on your Linux distribution and desktop environment.

You can also query a file type’s current default handler with xdg-mime. For example:

xdg-mime query default text/plain

This reports the desktop entry associated with plain-text files. To change a handler from the terminal, you need the correct desktop entry name for the application you want to use. Because those names vary, confirm the installed application’s desktop file before setting a new default. Changing an association affects future opens; it does not close a window that is already open.

If a URL opens in an unexpected browser, check your desktop’s default web browser setting and any application-specific preferences. After changing the default, test with a harmless URL before relying on the setting for important work.

Common Questions About Closing xdg-open

Can I close xdg-open with Ctrl+C? Yes, if it is still running in the foreground in the terminal where you started it. This interrupts the command, but it may not close the application or window that has already opened.

Does xdg-open stay open after launching a browser? Often, it exits soon after handing the request to the desktop or browser. Some systems use helper processes or portals, so the exact behavior can vary.

Will killing xdg-open close my browser? Usually not. The browser is generally a separate process. Close the browser tab or window normally, or manage the browser process only if the browser itself is stuck.

Is it safe to use pkill xdg-open? It may stop processes matching that name, but checking the process list and terminating a specific PID is more precise. Avoid broad process-matching commands when you are unsure what they will affect.

Why does xdg-open return an error even though the file opened? A desktop helper or handler may report a warning after the application has already received the request. Check whether the file opened successfully before assuming the launch failed.

Conclusion

To close xdg-open in the usual sense, close the browser, document viewer, or file manager that it launched. The command is typically a launcher, not a persistent windowed application, and there is no universal close subcommand. If the launcher itself is still running, inspect it with pgrep -af xdg-open, then use kill PID only after confirming the process. For a foreground command, Ctrl+C can interrupt it, but it may leave the opened app running. Using the application’s normal close controls is the safest and most reliable way to finish.


Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.

Shrewdnia

Shrewdnia

Shrewdnia is a destination for curious minds seeking clarity, knowledge, and informed perspectives. Through insightful articles and practical guides our passionate team explores a wide range of topics designed to help readers understand the world around them, make smarter decisions, and stay informed in an ever-changing landscape.


💡 Every question sparks discovery, and every perspective enriches the conversation. Share your thoughts and insights in the comments 👇

Back to blog

Leave a comment

JOIN THE SHREWDNIA COMMUNITY FORUM

What do you think?

Have an opinion, experience, or question about this topic? Join the Shrewdnia Forum and share your thoughts with other readers.

Join the Forum →