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.
6 Answers
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
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
The lsof
approach 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
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
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.
wget
is still running? (ps -ef | grep wget | grep -v grep
or similar)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.