I am trying to download a file with wget but in background and inside a screen that detaches ...

My initial command was:

wget http://www.example.com/file.zip -O temp/file.zip; mv temp/file.zip downloads/file.zip;

That would nicely move file once downloaded, preventing me from handling downloads/ files while they still download in background.

Now I need to run that in backgorund with screen, so I run and detach it:

screen -dm wget http://www.example.com/file.zip -O temp/file.zip;

But how can I still pass the move command and so that it runs when first one is completed ?

Edit: I tried quotes based on DopeGhoti's answer:

 screen -dm 'wget http://mirror.leaseweb.com/speedtest/100mb.bin -O 1.bin; mv 1.bin 2.bin'
 cannot identify account 'wget http:'.

and this:

 screen 'wget http://mirror.leaseweb.com/speedtest/100mb.bin -O 1.bin; mv 1.bin 2.bin'
 cannot exec 'wget http://mirror[...] no such file or directory

Edit: I tried with full /usr/bin/wget and /usr/bin/mv paths, it complains about missing session name, I gave it session name with -S foo, now it exits silently, no such screen to resume and no files downloaded:

screen -dm -S foo '/usr/bin/wget http://mirror.leaseweb.com/speedtest/100mb.bin -O 1.bin; /usr/bin/mv 1.bin 2.bin'
  • 3
    use screen -dm bash -c 'wget http://mirror... && mv 1.bin 2.bin'
    – meuh
    Jul 12, 2017 at 14:57
  • @meuh worked great, if you want to add it as an answer, I would accept it. Thank you.
    – adrianTNT
    Jul 14, 2017 at 12:18

2 Answers 2


It works if I specify bash -c

screen -dm bash -c 'command1; command2;'

User meuh provided this solution in comments, thanks.


Put the entire sequence of commands you're sending to screen in quotes; otherwise the first semicolon ends that command and sends the remainder to the shell in which you're invoking screen:

screen -dm 'wget http://www.example.com/file.zip -O temp/file.zip; mv temp/file.zip downloads/file.zip'

It might, though, be wise to only do the file move if the download is successful:

screen -dm 'if wget http://www.example.com/file.zip -O temp/file.zip; then mv temp/file.zip downloads/file.zip; fi'
  • I added details to the question; I tried the commands and I am getting errors with and without -dm, it reacts strange.
    – adrianTNT
    Jul 11, 2017 at 22:22
  • 2
    You need to add a bash -c as screen wont run the shell by default. (see my comment on original post).
    – meuh
    Jul 14, 2017 at 12:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .