在nohup
命令中设置工作目录,可以使用cd
命令先切换到目标目录,然后再执行你的程序
nohup bash -c 'cd /path/to/your/working/directory && your_command' &
这里,/path/to/your/working/directory
是你想要设置的工作目录,your_command
是你想要执行的命令。&
符号将命令放入后台运行。
例如,如果你想要在/home/user/my_project
目录下运行python main.py
,你可以这样操作:
nohup bash -c 'cd /home/user/my_project && python main.py' &
这将在后台运行python main.py
,并将工作目录设置为/home/user/my_project
。