How to close a terminal without closing the program run from it

Normally when you use the terminal for run a program, if you want close terminal, this will also close the running program. To avoid this behavior, there is a small trick.


Suppose you opened nautilus from a terminal by running:

Nautilus 

Now you want to close the terminal without closing the Nautilus window. To do this, press Ctrl + z in the terminal and run the following commands:

disown -h% 1  
bg 1 

Once that is done, you can close the terminal without affecting the program you opened from the terminal.

As Rafa (one of our readers) suggests, another similar method but that does not have exactly the same effects is to add the parameter & at the end of the command you want to execute. For example, to open nautilus it would be like this:

nautilus &

This means that you can continue to use the terminal after running the program but, unlike the previous method, closing the terminal will also close the executed program.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Javier García said

    xD already saved me this tips thank you very much again 😀

  2.   Javier García said

    Great, thanks a lot for the tips ^ __ ^

  3.   Ivan Escobares said

    It's a good tip ..

  4.   Sergio Esau Arámbula Duran said

    Good post

  5.   Let's use Linux said

    Thanks Envi! I already updated the article so that there are no doubts and to be clearer ...
    Hug! Paul.

  6.   Envi said

    This is not really so. The process runs in the background leaving the terminal free, but the moment the terminal closes the process ends.

  7.   Rafael said

    If you can do it as a script let's say that in bash how are the parameters then programs ./run nautilus
    then inside of you
    script #! / bin / bash
    $1 &

    then the $ 1 works as a parameter and passes it the name of the program you want to execute, or you modify it with the lines

    disown -h% 1
    bg 1 but there is everyone's taste I prefer nautils & o conky & greetings 😀

  8.   zagurito said

    I've been looking for this for a long time! Thank you so much for sharing it!

  9.   Let's use Linux said

    You are right Rafa! I have already incorporated your contribution in the article.
    Hug! Paul.

  10.   Roland Alvarado said

    As much as I tried it, it does not accept this command, but it works very well for me when I add "&" after the command to open the program "nautilus &"

  11.   Rafael said

    or simply put "nautilus &" and you can close the xD terminal because you leave it running in an independent process, that's what the "&" is for

  12.   Let's use Linux said

    Good tip!

  13.   Let's use Linux said

    Another good tip

  14.   guest said

    An alternative is to use programs like tmux or screen.

  15.   Juan said

    What exactly does each command mean? What do they do? 'bg' I imagine would be to put in BackGround whatever the console was.
    And thank you very much Pablo. It will be useful to many of us, I think.

  16.   nary said

    this trick is a bit cryptic the best is:
    nohup nautilus and now you can close the terminal, disown is to disassociate the jobs from the terminal. And if you want it to work in the background:
    nohup nautilus & and you can continue working in the terminal or close it.

  17.   Fernando Quintero said

    Is there a way to do it in a script?