How can I run a Linux command that still runs after I close my PuTTY SSH session?

后端 未结 4 1628
情话喂你
情话喂你 2021-01-15 05:26

I am connecting to my NAS over putty which is running linux on it.

I wanted to move a big directory from one location to another. Is it possible to keep the process

相关标签:
4条回答
  • 2021-01-15 06:03

    Start your task with 'nohup' and put it in the background with '&', e.g.:

    $ nohup mv /here /there &
    $ exit
    

    and it should continue running.

    0 讨论(0)
  • 2021-01-15 06:11

    Using nohup would be best solution.

    The following command in your terminal may help you out to run the script using nohup and redirect the output in your desired file.

    General Syntax

    nohup some_command &> nohup_log_file_name.out &
    

    Example

    nohup python script.py &> nohup_log_script.out & 
    

    So, if you use the above command, you will be able to find the outputs of the command in a log file named nohup_log_script.out

    0 讨论(0)
  • 2021-01-15 06:16

    You can run it as a background process as follows:

    nohup mv source target &

    However, you will not be able to interact with the process.

    EDIT: nohup is also required to keep it running after the shell exits.

    0 讨论(0)
  • 2021-01-15 06:19

    I would suggest using screen for this.

    Start a new screen,

    screen -S <name of your screen>

    and then you can perform your commands there, detach from the screen and re-attach to it at any time.

    Detach by hitting the sequence

    ctrl a d

    and re-attach by typing

    screen -r (or list the screens with screen -l).

    Also have a look at Gnu screen survival guide.

    0 讨论(0)
提交回复
热议问题