How to know if file is already finished downloading in linux command line?












3















If you're downloading a large file in linux via command line, is there a command to know if it's already completed? Currently I am only checking if the file size is the same as the expected file size but what if you don't know the expected file size? Currently ls shows the exact file name (i.e., file.zip) instead of something like file.zip.temp or something even if the file is currently downloading.










share|improve this question























  • Couldn't you just check whether wget is still running? (ps -ef | grep wget | grep -v grep or similar)

    – slhck
    Oct 21 '12 at 13:06













  • @slhck looks like that ninja code will do the job

    – IMB
    Oct 21 '12 at 13:21











  • You can also use iftop command that will show you active connection and the volume of network traffic. If you have a single download file per destination IP, you will be able to see when the transfer finishes.

    – mnmnc
    Aug 11 '15 at 10:32
















3















If you're downloading a large file in linux via command line, is there a command to know if it's already completed? Currently I am only checking if the file size is the same as the expected file size but what if you don't know the expected file size? Currently ls shows the exact file name (i.e., file.zip) instead of something like file.zip.temp or something even if the file is currently downloading.










share|improve this question























  • Couldn't you just check whether wget is still running? (ps -ef | grep wget | grep -v grep or similar)

    – slhck
    Oct 21 '12 at 13:06













  • @slhck looks like that ninja code will do the job

    – IMB
    Oct 21 '12 at 13:21











  • You can also use iftop command that will show you active connection and the volume of network traffic. If you have a single download file per destination IP, you will be able to see when the transfer finishes.

    – mnmnc
    Aug 11 '15 at 10:32














3












3








3


1






If you're downloading a large file in linux via command line, is there a command to know if it's already completed? Currently I am only checking if the file size is the same as the expected file size but what if you don't know the expected file size? Currently ls shows the exact file name (i.e., file.zip) instead of something like file.zip.temp or something even if the file is currently downloading.










share|improve this question














If you're downloading a large file in linux via command line, is there a command to know if it's already completed? Currently I am only checking if the file size is the same as the expected file size but what if you don't know the expected file size? Currently ls shows the exact file name (i.e., file.zip) instead of something like file.zip.temp or something even if the file is currently downloading.







linux command-line debian wget






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Oct 21 '12 at 13:00









IMBIMB

2,464185991




2,464185991













  • Couldn't you just check whether wget is still running? (ps -ef | grep wget | grep -v grep or similar)

    – slhck
    Oct 21 '12 at 13:06













  • @slhck looks like that ninja code will do the job

    – IMB
    Oct 21 '12 at 13:21











  • You can also use iftop command that will show you active connection and the volume of network traffic. If you have a single download file per destination IP, you will be able to see when the transfer finishes.

    – mnmnc
    Aug 11 '15 at 10:32



















  • Couldn't you just check whether wget is still running? (ps -ef | grep wget | grep -v grep or similar)

    – slhck
    Oct 21 '12 at 13:06













  • @slhck looks like that ninja code will do the job

    – IMB
    Oct 21 '12 at 13:21











  • You can also use iftop command that will show you active connection and the volume of network traffic. If you have a single download file per destination IP, you will be able to see when the transfer finishes.

    – mnmnc
    Aug 11 '15 at 10:32

















Couldn't you just check whether wget is still running? (ps -ef | grep wget | grep -v grep or similar)

– slhck
Oct 21 '12 at 13:06







Couldn't you just check whether wget is still running? (ps -ef | grep wget | grep -v grep or similar)

– slhck
Oct 21 '12 at 13:06















@slhck looks like that ninja code will do the job

– IMB
Oct 21 '12 at 13:21





@slhck looks like that ninja code will do the job

– IMB
Oct 21 '12 at 13:21













You can also use iftop command that will show you active connection and the volume of network traffic. If you have a single download file per destination IP, you will be able to see when the transfer finishes.

– mnmnc
Aug 11 '15 at 10:32





You can also use iftop command that will show you active connection and the volume of network traffic. If you have a single download file per destination IP, you will be able to see when the transfer finishes.

– mnmnc
Aug 11 '15 at 10:32










6 Answers
6






active

oldest

votes


















6














If you're downloading with wget, you can simply check if the instance is still running:




ps -ef | grep wget | grep -v grep


Also, you could check whether the file is still opened by wget. Obviously, replace the path here.




lsof /path/to/downloaded/file





share|improve this answer































    3














    If you do not need to execute wget in background, do not do it, it will only lead to complications.



    I advocate against solutions like checking ps -C wget or pidof wget (shorter, perhaps non-POSIX, equivalents to ps -ef | grep wget | grep -v grep), since they will consider any wget and not only the one you are interested in, which might be an unassumable assumption if your machine does not only do one task.



    If you are inside a script, you can wget & WGETPID=$! and then check that PID. Or you could simply wait, which would wait for your background processes to finish.



    It might be important to do something in order to distinguish between a successful and unsuccessful download. if wget ... ; then touch wget_ok ; else touch wget_error ; fi






    share|improve this answer































      2














      What if you are running more than one wget command?



      If you need to accommodate for this scenario, then you could do a few different things:




      • You could pipe the progress to a file with a known name and check that.

      • You could force the idea you had in your question, download to a temporary file, then in a a second command rename it.


      • You could just write a token after the process is completed, i.e.



        wget 'file'; touch file.is.done







      share|improve this answer

































        1














        The lsofapproach suggested by slhck is probably the best way. If you want to use the other suggestions involving creating a file once the download is complete, use && instead of ; so that a report is generated only if the download exits correctly:



        wget file && touch file.is.done





        share|improve this answer

































          0














          I'd like rather sound signal, so if i start a long operation (not only wget but any time resourse consuming) that i don't want watch instantaneously i use something like



          `LONG_COMMAND && SOUND_OK || SOUND_ERROR`


          so even if i need to know immediately when it finishes i'll also be able to do something else the same time without interrupting myself time to time for the checking, i just can hear result (of SOUND_OK if first command exit status is 0 and SOUND_ERROR in other case) and check it only once when it finishes. You can even continue current activity if only you need to know is that your task finished. LONG_COMMAND could be wget, and as SOUND_OK i prefer echo -e "a" >/dev/console but you can use command to play any audio sample.



          As long as wget can produce several different exit codes, one can use them to determine the alarm command in "bios-style" as follows



          wget URL;
          CODE=$?;
          beep;
          [ $CODE -gt 0 ] && while true; do
          for peek in `seq 1 $CODE`; do
          beep; sleep 1;done
          sleep 3; done





          share|improve this answer

































            0














            you could start wget with -o dl.log option i.e. to define a log file which you can periodically check to see if you'll see (using regular expression) this line.



            12:59:48 (126.32 MB/s) - `/path/to/downloaded/file/some_file.zip' saved [95235097/95235097]


            actually, you can use "tail dl.log" to get only the last few lines instead of reading the whole thing.






            share|improve this answer























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "3"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f490601%2fhow-to-know-if-file-is-already-finished-downloading-in-linux-command-line%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              6 Answers
              6






              active

              oldest

              votes








              6 Answers
              6






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              6














              If you're downloading with wget, you can simply check if the instance is still running:




              ps -ef | grep wget | grep -v grep


              Also, you could check whether the file is still opened by wget. Obviously, replace the path here.




              lsof /path/to/downloaded/file





              share|improve this answer




























                6














                If you're downloading with wget, you can simply check if the instance is still running:




                ps -ef | grep wget | grep -v grep


                Also, you could check whether the file is still opened by wget. Obviously, replace the path here.




                lsof /path/to/downloaded/file





                share|improve this answer


























                  6












                  6








                  6







                  If you're downloading with wget, you can simply check if the instance is still running:




                  ps -ef | grep wget | grep -v grep


                  Also, you could check whether the file is still opened by wget. Obviously, replace the path here.




                  lsof /path/to/downloaded/file





                  share|improve this answer













                  If you're downloading with wget, you can simply check if the instance is still running:




                  ps -ef | grep wget | grep -v grep


                  Also, you could check whether the file is still opened by wget. Obviously, replace the path here.




                  lsof /path/to/downloaded/file






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Oct 21 '12 at 13:38









                  slhckslhck

                  160k47444466




                  160k47444466

























                      3














                      If you do not need to execute wget in background, do not do it, it will only lead to complications.



                      I advocate against solutions like checking ps -C wget or pidof wget (shorter, perhaps non-POSIX, equivalents to ps -ef | grep wget | grep -v grep), since they will consider any wget and not only the one you are interested in, which might be an unassumable assumption if your machine does not only do one task.



                      If you are inside a script, you can wget & WGETPID=$! and then check that PID. Or you could simply wait, which would wait for your background processes to finish.



                      It might be important to do something in order to distinguish between a successful and unsuccessful download. if wget ... ; then touch wget_ok ; else touch wget_error ; fi






                      share|improve this answer




























                        3














                        If you do not need to execute wget in background, do not do it, it will only lead to complications.



                        I advocate against solutions like checking ps -C wget or pidof wget (shorter, perhaps non-POSIX, equivalents to ps -ef | grep wget | grep -v grep), since they will consider any wget and not only the one you are interested in, which might be an unassumable assumption if your machine does not only do one task.



                        If you are inside a script, you can wget & WGETPID=$! and then check that PID. Or you could simply wait, which would wait for your background processes to finish.



                        It might be important to do something in order to distinguish between a successful and unsuccessful download. if wget ... ; then touch wget_ok ; else touch wget_error ; fi






                        share|improve this answer


























                          3












                          3








                          3







                          If you do not need to execute wget in background, do not do it, it will only lead to complications.



                          I advocate against solutions like checking ps -C wget or pidof wget (shorter, perhaps non-POSIX, equivalents to ps -ef | grep wget | grep -v grep), since they will consider any wget and not only the one you are interested in, which might be an unassumable assumption if your machine does not only do one task.



                          If you are inside a script, you can wget & WGETPID=$! and then check that PID. Or you could simply wait, which would wait for your background processes to finish.



                          It might be important to do something in order to distinguish between a successful and unsuccessful download. if wget ... ; then touch wget_ok ; else touch wget_error ; fi






                          share|improve this answer













                          If you do not need to execute wget in background, do not do it, it will only lead to complications.



                          I advocate against solutions like checking ps -C wget or pidof wget (shorter, perhaps non-POSIX, equivalents to ps -ef | grep wget | grep -v grep), since they will consider any wget and not only the one you are interested in, which might be an unassumable assumption if your machine does not only do one task.



                          If you are inside a script, you can wget & WGETPID=$! and then check that PID. Or you could simply wait, which would wait for your background processes to finish.



                          It might be important to do something in order to distinguish between a successful and unsuccessful download. if wget ... ; then touch wget_ok ; else touch wget_error ; fi







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Oct 22 '12 at 8:58









                          Raúl Salinas-MonteagudoRaúl Salinas-Monteagudo

                          970610




                          970610























                              2














                              What if you are running more than one wget command?



                              If you need to accommodate for this scenario, then you could do a few different things:




                              • You could pipe the progress to a file with a known name and check that.

                              • You could force the idea you had in your question, download to a temporary file, then in a a second command rename it.


                              • You could just write a token after the process is completed, i.e.



                                wget 'file'; touch file.is.done







                              share|improve this answer






























                                2














                                What if you are running more than one wget command?



                                If you need to accommodate for this scenario, then you could do a few different things:




                                • You could pipe the progress to a file with a known name and check that.

                                • You could force the idea you had in your question, download to a temporary file, then in a a second command rename it.


                                • You could just write a token after the process is completed, i.e.



                                  wget 'file'; touch file.is.done







                                share|improve this answer




























                                  2












                                  2








                                  2







                                  What if you are running more than one wget command?



                                  If you need to accommodate for this scenario, then you could do a few different things:




                                  • You could pipe the progress to a file with a known name and check that.

                                  • You could force the idea you had in your question, download to a temporary file, then in a a second command rename it.


                                  • You could just write a token after the process is completed, i.e.



                                    wget 'file'; touch file.is.done







                                  share|improve this answer















                                  What if you are running more than one wget command?



                                  If you need to accommodate for this scenario, then you could do a few different things:




                                  • You could pipe the progress to a file with a known name and check that.

                                  • You could force the idea you had in your question, download to a temporary file, then in a a second command rename it.


                                  • You could just write a token after the process is completed, i.e.



                                    wget 'file'; touch file.is.done








                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited Oct 21 '12 at 14:09









                                  slhck

                                  160k47444466




                                  160k47444466










                                  answered Oct 21 '12 at 13:56









                                  NickNick

                                  1861111




                                  1861111























                                      1














                                      The lsofapproach suggested by slhck is probably the best way. If you want to use the other suggestions involving creating a file once the download is complete, use && instead of ; so that a report is generated only if the download exits correctly:



                                      wget file && touch file.is.done





                                      share|improve this answer






























                                        1














                                        The lsofapproach suggested by slhck is probably the best way. If you want to use the other suggestions involving creating a file once the download is complete, use && instead of ; so that a report is generated only if the download exits correctly:



                                        wget file && touch file.is.done





                                        share|improve this answer




























                                          1












                                          1








                                          1







                                          The lsofapproach suggested by slhck is probably the best way. If you want to use the other suggestions involving creating a file once the download is complete, use && instead of ; so that a report is generated only if the download exits correctly:



                                          wget file && touch file.is.done





                                          share|improve this answer















                                          The lsofapproach suggested by slhck is probably the best way. If you want to use the other suggestions involving creating a file once the download is complete, use && instead of ; so that a report is generated only if the download exits correctly:



                                          wget file && touch file.is.done






                                          share|improve this answer














                                          share|improve this answer



                                          share|improve this answer








                                          edited Mar 20 '17 at 10:16









                                          Community

                                          1




                                          1










                                          answered Oct 24 '12 at 12:35









                                          terdonterdon

                                          41.3k887136




                                          41.3k887136























                                              0














                                              I'd like rather sound signal, so if i start a long operation (not only wget but any time resourse consuming) that i don't want watch instantaneously i use something like



                                              `LONG_COMMAND && SOUND_OK || SOUND_ERROR`


                                              so even if i need to know immediately when it finishes i'll also be able to do something else the same time without interrupting myself time to time for the checking, i just can hear result (of SOUND_OK if first command exit status is 0 and SOUND_ERROR in other case) and check it only once when it finishes. You can even continue current activity if only you need to know is that your task finished. LONG_COMMAND could be wget, and as SOUND_OK i prefer echo -e "a" >/dev/console but you can use command to play any audio sample.



                                              As long as wget can produce several different exit codes, one can use them to determine the alarm command in "bios-style" as follows



                                              wget URL;
                                              CODE=$?;
                                              beep;
                                              [ $CODE -gt 0 ] && while true; do
                                              for peek in `seq 1 $CODE`; do
                                              beep; sleep 1;done
                                              sleep 3; done





                                              share|improve this answer






























                                                0














                                                I'd like rather sound signal, so if i start a long operation (not only wget but any time resourse consuming) that i don't want watch instantaneously i use something like



                                                `LONG_COMMAND && SOUND_OK || SOUND_ERROR`


                                                so even if i need to know immediately when it finishes i'll also be able to do something else the same time without interrupting myself time to time for the checking, i just can hear result (of SOUND_OK if first command exit status is 0 and SOUND_ERROR in other case) and check it only once when it finishes. You can even continue current activity if only you need to know is that your task finished. LONG_COMMAND could be wget, and as SOUND_OK i prefer echo -e "a" >/dev/console but you can use command to play any audio sample.



                                                As long as wget can produce several different exit codes, one can use them to determine the alarm command in "bios-style" as follows



                                                wget URL;
                                                CODE=$?;
                                                beep;
                                                [ $CODE -gt 0 ] && while true; do
                                                for peek in `seq 1 $CODE`; do
                                                beep; sleep 1;done
                                                sleep 3; done





                                                share|improve this answer




























                                                  0












                                                  0








                                                  0







                                                  I'd like rather sound signal, so if i start a long operation (not only wget but any time resourse consuming) that i don't want watch instantaneously i use something like



                                                  `LONG_COMMAND && SOUND_OK || SOUND_ERROR`


                                                  so even if i need to know immediately when it finishes i'll also be able to do something else the same time without interrupting myself time to time for the checking, i just can hear result (of SOUND_OK if first command exit status is 0 and SOUND_ERROR in other case) and check it only once when it finishes. You can even continue current activity if only you need to know is that your task finished. LONG_COMMAND could be wget, and as SOUND_OK i prefer echo -e "a" >/dev/console but you can use command to play any audio sample.



                                                  As long as wget can produce several different exit codes, one can use them to determine the alarm command in "bios-style" as follows



                                                  wget URL;
                                                  CODE=$?;
                                                  beep;
                                                  [ $CODE -gt 0 ] && while true; do
                                                  for peek in `seq 1 $CODE`; do
                                                  beep; sleep 1;done
                                                  sleep 3; done





                                                  share|improve this answer















                                                  I'd like rather sound signal, so if i start a long operation (not only wget but any time resourse consuming) that i don't want watch instantaneously i use something like



                                                  `LONG_COMMAND && SOUND_OK || SOUND_ERROR`


                                                  so even if i need to know immediately when it finishes i'll also be able to do something else the same time without interrupting myself time to time for the checking, i just can hear result (of SOUND_OK if first command exit status is 0 and SOUND_ERROR in other case) and check it only once when it finishes. You can even continue current activity if only you need to know is that your task finished. LONG_COMMAND could be wget, and as SOUND_OK i prefer echo -e "a" >/dev/console but you can use command to play any audio sample.



                                                  As long as wget can produce several different exit codes, one can use them to determine the alarm command in "bios-style" as follows



                                                  wget URL;
                                                  CODE=$?;
                                                  beep;
                                                  [ $CODE -gt 0 ] && while true; do
                                                  for peek in `seq 1 $CODE`; do
                                                  beep; sleep 1;done
                                                  sleep 3; done






                                                  share|improve this answer














                                                  share|improve this answer



                                                  share|improve this answer








                                                  edited Oct 9 '14 at 1:08

























                                                  answered Oct 9 '14 at 0:10









                                                  Leben GlebenLeben Gleben

                                                  555




                                                  555























                                                      0














                                                      you could start wget with -o dl.log option i.e. to define a log file which you can periodically check to see if you'll see (using regular expression) this line.



                                                      12:59:48 (126.32 MB/s) - `/path/to/downloaded/file/some_file.zip' saved [95235097/95235097]


                                                      actually, you can use "tail dl.log" to get only the last few lines instead of reading the whole thing.






                                                      share|improve this answer




























                                                        0














                                                        you could start wget with -o dl.log option i.e. to define a log file which you can periodically check to see if you'll see (using regular expression) this line.



                                                        12:59:48 (126.32 MB/s) - `/path/to/downloaded/file/some_file.zip' saved [95235097/95235097]


                                                        actually, you can use "tail dl.log" to get only the last few lines instead of reading the whole thing.






                                                        share|improve this answer


























                                                          0












                                                          0








                                                          0







                                                          you could start wget with -o dl.log option i.e. to define a log file which you can periodically check to see if you'll see (using regular expression) this line.



                                                          12:59:48 (126.32 MB/s) - `/path/to/downloaded/file/some_file.zip' saved [95235097/95235097]


                                                          actually, you can use "tail dl.log" to get only the last few lines instead of reading the whole thing.






                                                          share|improve this answer













                                                          you could start wget with -o dl.log option i.e. to define a log file which you can periodically check to see if you'll see (using regular expression) this line.



                                                          12:59:48 (126.32 MB/s) - `/path/to/downloaded/file/some_file.zip' saved [95235097/95235097]


                                                          actually, you can use "tail dl.log" to get only the last few lines instead of reading the whole thing.







                                                          share|improve this answer












                                                          share|improve this answer



                                                          share|improve this answer










                                                          answered Aug 11 '15 at 10:05









                                                          Svetoslav MarinovSvetoslav Marinov

                                                          1012




                                                          1012






























                                                              draft saved

                                                              draft discarded




















































                                                              Thanks for contributing an answer to Super User!


                                                              • Please be sure to answer the question. Provide details and share your research!

                                                              But avoid



                                                              • Asking for help, clarification, or responding to other answers.

                                                              • Making statements based on opinion; back them up with references or personal experience.


                                                              To learn more, see our tips on writing great answers.




                                                              draft saved


                                                              draft discarded














                                                              StackExchange.ready(
                                                              function () {
                                                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f490601%2fhow-to-know-if-file-is-already-finished-downloading-in-linux-command-line%23new-answer', 'question_page');
                                                              }
                                                              );

                                                              Post as a guest















                                                              Required, but never shown





















































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown

































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown







                                                              Popular posts from this blog

                                                              Mouse cursor on multiple screens with different PPI

                                                              Agildo Ribeiro

                                                              Sometime when accessing a menu: “Ubuntu 16.04 has experienced an internal error”