Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
get the length of a remote file
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
ev56o
Apprentice
Apprentice


Joined: 26 Jan 2010
Posts: 180

PostPosted: Wed Dec 03, 2014 11:00 am    Post subject: get the length of a remote file Reply with quote

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
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6228
Location: Room 101

PostPosted: Wed Dec 03, 2014 11:18 am    Post subject: Re: get the length of a remote file Reply with quote

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
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 5591

PostPosted: Wed Dec 03, 2014 4:34 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum