nohup command & can keep a command running after closing the terminal.
I want to play all mp3 music in directory Music.
ls Music/*mp3 |xargs -d "\n" mplayer
ls Music/*mp3 can list all mp3 files in directory Music, send it via pipe with xargs, -d "\n" is to treat blanks in the filenames.
I want to redirect all stdout and stderr into /dev/null, and run it in the background.
ls Music/*mp3 |xargs -d "\n" mplayer > /dev/null 2>&1 &
This works fine, but I want it running after closing the terminal.
nohup ls Music/*mp3 | xargs -d "\n" mplayer > /dev/null 2>&1 &
ls Music/*mp3 | xargs -d "\n" nohup mplayer > /dev/null 2>&1 &
ls Music/*mp3 | nohup xargs -d "\n" mplayer > /dev/null 2>&1 &
When I close the terminal, the process running in the background ends.
Why does nohup not take effect in any of the above three commands? How can I make it take effect?
disown can solve the issue, but I would like a solution using nohup.
ls Music/*mp3 | xargs -d "\n" mplayer > /dev/null 2>&1 & disown
