5

Could someone remind me how do I run application through the terminal, which allow me to close the terminal after the program is open. I totally forgot how to do this. Please let me know.

Radu Rădeanu
  • 169,590
  • 1
    This as not been answered. Is not the Answer am looking for. If it was I would have not posted this, as I have seen those posts before. –  Mar 05 '14 at 18:39
  • @Braiam I don't think this Q is duplicate. I think that the OP wants a command *which allows to close terminal after the program is open*. – Radu Rădeanu Mar 05 '14 at 18:40
  • @RaduRădeanu and nohup doesn't? – Braiam Mar 05 '14 at 18:41
  • 1
    @user242294 can you explain exactly your need. it seems confusing for the community – kamil Mar 05 '14 at 18:47
  • There's a variety of methods you could use. The disown command is popular, but I've never been a fan of it. Personally, I prefer to use a multiplexer like Tmux, although screen would work as well. – Jacobm001 Mar 05 '14 at 18:17
  • A few months ago, my lecturer showed me a command that actually does it all, like with nohup you still have to press ctrl-c to skip to the next line. My lecturer showed me one that does everything. I was able to open an txt editor and then actually carry on with the same window. –  Mar 05 '14 at 19:06
  • 1
    @user242294 The confusion is about: do you want that the terminal to be closed manually or automatically? – Radu Rădeanu Mar 05 '14 at 19:10
  • @Braiam nohup doesn't close the terminal ;) – Radu Rădeanu Mar 05 '14 at 20:08
  • @user242294 with nohup you don't need to press ctrl+c to skip to the next line. simply click enter and see that have just run the program (like firefox) and you still have control on the terminal. Try it – kamil Mar 06 '14 at 13:30

2 Answers2

6
(command &) && exit

Example:

(firefox &) && exit
Radu Rădeanu
  • 169,590
2

I think this is the best way:

nohup (command) &> /dev/null & 

example:

nohup firefox &> /dev/null &

Edit: the "&> /dev/null &" redirects the output of nohup such that you do not have logs (nohup.out) See https://unix.stackexchange.com/questions/23010/how-to-make-nohup-not-create-any-output-files-and-so-not-eat-all-space

enter image description here

Then I can close terminal without a warning message either by the exit command or by clicking the x on the terminal window

kamil
  • 7,355
  • 7
  • 40
  • 61
  • 1
    Added information to prevent "nohup.out" log files. An alternate to nohup is disown or running your applications in screen, depending on what you want to do. screen tends to work well with ssh. – Panther Mar 05 '14 at 18:35
  • the OP said: "allow me to close the terminal" not "close terminal automatically" – kamil Mar 05 '14 at 18:45
  • >& is not a syntax error. – Olli Mar 05 '14 at 19:12
  • @Olli then why you did the edit. by the way both works – kamil Mar 05 '14 at 19:13
  • I didn't edit it, rolled back the edit by @terdon – Olli Mar 05 '14 at 19:15
  • @Olli yes, please roll back again. &> means redirect both standard error and standard output, it is shorthand for 2>&1 >, >& means redirect to a file called & which, since & is a special character for bash, will give an error for most commands and works only by chance on the nohup. That is not a good reason to keep a syntax error in an answer. Compare ls >& /dev/null and ls &> /dev/null. – terdon Mar 05 '14 at 19:19
  • @Olli also, while this is most certainly a syntax error, it does seem to "work" in the specific case of nohup when running in any of bash,zsh, tcsh or csh but fails in dash, ` ksh and fish. More details in my question on [unix.se]. – terdon Mar 05 '14 at 20:08