View previous topic :: View next topic |
Author |
Message |
ev56o Apprentice

Joined: 26 Jan 2010 Posts: 180
|
Posted: Wed Dec 03, 2014 11:00 am Post subject: get the length of a remote file |
|
|
i need to know the length (in byte) of a remote file before download.
i need a command similar:
Code: |
$ command http://bla.com/file.rar
14340 <-------the length of the file
|
this program must be faster and light than wget.
thanks. |
|
Back to top |
|
 |
khayyam Watchman


Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Wed Dec 03, 2014 11:18 am Post subject: Re: get the length of a remote file |
|
|
ev56o wrote: | i need to know the length (in byte) of a remote file before download. [...] this program must be faster and light than wget. |
ev56o ... you mean "faster" than actually downloading the file with wget? I assume so, you can use '--spider' and grab the "Length" string like so:
Code: | # wget --spider http://mirror.netcologne.de/gentoo/distfiles/layman-2.0.0.tar.gz 2>&1 | awk '/^Length/{print $2}'
81184 |
best ... khay |
|
Back to top |
|
 |
Ant P. Watchman

Joined: 18 Apr 2009 Posts: 6885
|
Posted: Wed Dec 03, 2014 4:34 pm Post subject: |
|
|
Alternatively:
Code: | $ curl -I http://mirror.netcologne.de/gentoo/distfiles/layman-2.0.0.tar.gz | pcregrep -o '(?<=Content-Length: )\d+'
81184 |
|
|
Back to top |
|
 |
|