46

When we want to open an application or file from the terminal, we type, say,

okular file.dvi

This opens the application, but also shows the status of the application. We cannot close the terminal, because it kills the process. Unfortunately, if you're trying to, for example, create a LaTeX file, you will need one tab for the text editor, one for the dvi file, and so on. And if you're trying to open all windows from the terminal, you can forget it. I'm trying use the terminal as much as possible, and while I have Yakuake, it is still a bother having so many tabs and seeing which of those have an application I've killed and so on.

So, is there a way to open an application/file from the terminal so that the status doesn't show and immediately gives the prompt so that we can use it to open more applications?

Seth
  • 58,122
notablytipsy
  • 2,927
  • Given your requests, regarding not seeing any output, the viewer not being a child processes of the terminal, etc, it seems an ideal candidate for when simply using a keyboard shortcut to open the viewer, or using e.g. grun to also pass in the filename, would be more suitable than sticking to using a terminal. – jmetz Jul 23 '12 at 18:04
  • I don't mind not seeing any output... I mind having to have multiple terminals/tabs open for multiple applications. The answer I have chosen suits all my preferences perfectly. – notablytipsy Jul 23 '12 at 18:15

4 Answers4

80
xdg-open file.dvi

xdg-open will open any file with its default application. As a bonus, you can close the terminal without killing the application.

Since xdg-open is quite a long name, I put an alias for it in .bashrc:

alias open='xdg-open'
  • Sweet! This is the best, even better than the one I had selected! And you get a 'Revival' badge :) – notablytipsy Aug 01 '12 at 08:04
  • Simple awesome ! – Yugal Jindle Dec 26 '13 at 06:25
  • Just want to point out that since this doesn't actually run the program, it means you can open the file without creating a new instance of that program. This means you can open a file and it will automatically be opened in the already open instance of the app. – Arc676 Jan 09 '17 at 10:27
  • 2
    if you recently move from mac to linux, it you probably be a good idea to do

    alias open="xdg-open"

    – Pedro Luz Oct 12 '18 at 11:17
  • quick tip in case of zsh: command not found: xdg-open: run sudo apt-get install --reinstall xdg-utils – Salomanuel Mar 13 '23 at 17:46
18
okular file.dvi &

just append an & to make your command running as separate process.

user827992
  • 2,851
  • Wow! Perfect! Funny... I searched Google for "open from terminal without showing status," never thought that it behaved like a separate process! Unfortunately, it says I have to wait for 8 minutes, so... – notablytipsy Jul 23 '12 at 17:33
14

okular file.dvi &> /dev/null & would be a bit better. This way, the program does not write to the terminal.

If you use just okular file.dvi & the program will still report things on the terminal, often in the middle of your work

josinalvo
  • 6,947
  • 5
  • 37
  • 51
6

With, say, evince file.pdf &, closing the terminal will still close the process, so that it is still a child process of the terminal and has no independence of it; nohup evince file.pdf & will allow you to close the terminal without the program closing as nohup means that any signals for the process to close (hangup) will be ignored. You can also disown a process in a similar way, see this discussion here.

  • Thanks, I didn't know that. I use Yakuake, and I never close it, so it's not a problem. But it's always useful to know such things. – notablytipsy Jul 23 '12 at 18:03
  • I just edited my post- see the difference- it will work now –  Jul 23 '12 at 18:07
  • Sorry - I had forgotten to put the & at the end :) – notablytipsy Jul 23 '12 at 18:08
  • 1
    When I try evince file.pdf &, it doesn't kill the process when I quit the terminal... – notablytipsy Jul 23 '12 at 18:11
  • When I quit the terminal on my machine, it does quit evince as well, e.g. with evince mplayer.pdf & –  Jul 23 '12 at 18:13
  • Hm. Dunno why it doesn't for me? But I see that you're right, from the Wikipedia article on it. – notablytipsy Jul 23 '12 at 18:15
  • I don't know-it's odd. The processes are both definitely gone after looking at the system monitor. –  Jul 23 '12 at 18:19
  • I even checked the system monitor to see if it was running in the background even after I quit it... nothing. – notablytipsy Jul 23 '12 at 18:21
  • 1
    When you start a child process, it belongs to the parent process. In this case, evince is the child process belonging to the terminal. Hence, when you close the terminal, it also closes the child processes. nohup separates this ownership, so it is what to use if you want to close the terminal. However, by default, nohup creates a file nohup.out in your home folder. If you don't want that file, use redirection as follows: nohup evince file.pdf &>/dev/null & – Paddy Landau Jul 31 '12 at 09:11