osx - Is there any way to get the size of a remote file without downloading it?

08
2013-08
  • Wuffers

    Is it at all possible to get the size of a remote file without downloading it? The file is over HTTP, not (S)FTP. I want to know this because I want to download something while connected with a limited 3G wireless plan and I don't want to use all my bandwidth in one pop. I have no access to the server, at all. So I can't do anything server-side. I am on Mac OS X. Solutions that make use of the command line are a plus, but not required.

    By the way, the specific file I want information for is the MP3 download from this website.

  • Answers
  • Matthieu Cartier

    You can do this by getting the Content-Length header, so long as it is HTTP.

    One way of doing this on the command line is with curl, for example:

    chris@chris-laptop:~$ curl -I -L http://www.fakkelbrigade.eu/chris/movies/drosovol1_final_h264_download.mp4
    HTTP/1.1 200 OK
    Date: Tue, 25 Jan 2011 22:22:51 GMT
    Server: Apache/2.2.16 (Debian)
    Last-Modified: Tue, 11 Jan 2011 16:32:52 GMT
    ETag: "3aa003-1b0c3479-49994a2c6f500"
    Accept-Ranges: bytes
    Content-Length: 453784697
    Content-Disposition: attachment
    Content-Type: application/octet-stream
    

    Content-Length is in bytes.

  • Daniel Beck

    You can issue HTTP HEAD requests to get the only header data. Content-Length is what you want.

    $ telnet superuser.com 80
    Trying 64.34.119.12...
    Connected to superuser.com.
    Escape character is '^]'.
    HEAD / HTTP/1.0
    
    HTTP/1.1 302 Found
    Content-Length: 141
    Location: http://stackexchange.com
    Date: Tue, 25 Jan 2011 22:21:28 GMT
    Connection: close
    
  • tobylane

    It depends on how the server is setup and the file. With most files the server sends it in the headers, but it may be a dynamic file and therefore it doesn't know (and your browser can't guess how long it will take.

    tobylane$ telnet stackexchange.com 80

    Trying 64.34.119.12...

    Connected to stackexchange.com.

    Escape character is '^]'.

    GET /

    HTTP/1.1 302 Found

    Location: http://stackexchange.com

    Date: Tue, 25 Jan 2011 22:01:22 GMT

    Connection: close

    I'm not sure what a good request is (GET / worked on other sites), but I hope this helps.


  • Related Question

    osx - Sort All Files (any depth) within a Folder by Size
  • Željko Filipin

    I have a folder full of folders and files. I want to sort files by size (so I could remove the largest files).

    I know how to do that in Windows Explorer, but I can not find a way to do it in Mac OS X Finder.

    Windows 2003:

    • open folder in Windows Explorer
    • click button Search
    • leave Search for files or folders named and Containing text text fields empty
    • click button Search Now
    • sort by size

    Is there a way to do something like this in Finder on Mac OS X?


  • Related Answers
  • dertoni

    Open Terminal, cd to the folder you want to analyze and use this command:

    find . -type f -print0 | xargs -0 ls -l | sort -k5,5rn
    

    It should print a list of all files in the hierarchy, sorted by size. At least on my machine, which is not a Mac, but some other Unix. But in principal it should be roughly the same.

    Thanks to Richard Hoskins for the bug with the spaces in the names. That's actually a feature in xargs. See this site where it's explained quite nicely. Above version should work now.

    Edit

    Here is an explanation how the command works:

    find . ==> find items from current working directory "."

    -type f ==> search for regular files

    -print0 ==> print full file name to standard out, ending with a null character, instead of newline (this is for handling filenames with newlines and white space by xargs)

    xargs ==> execute command xargs (executes a command for every line in standard in)

    -0 ==> line delimiter is null character

    ls -l ==> the command for xargs to execute. This way we get the details especially the size of the files.

    sort ==> sort lines in standard in

    -k5,5rn ==> sort field definition, begin at field 5 (delimiter default is blank) and end at field 5. That's the size field in ls -l display. r stands for reverse sort order, so that the biggest files are on top and n stands for numerical sort order.

  • 8088

    Assuming it's just a folder, open the folder in Finder. Then click the "Detail" view button. Finally, click the "Size" column. The largest files will sort to the top. Additionally, folders within this folder are also sorted by size -- simply click the triangle next to them, and you will see their files sorted as well. (Don't "open" the folder by double-clicking, just click the triangle to expand their contents.)

    Screen Shot

    If you wanted to do a search, you can search by file size. Go to the File menu, and choose Find. Click the list that starts out saying "Kind," and choose "Other." Select Size from the list that comes up. Enter your criteria and search. However, I cannot find a way to make the search results display the file size column, so it's easier to use that to, say, find files greater than a certain size than to actually sort by size.

  • Željko Filipin
    • open Finder
    • go to folder
    • Finder > File > Find...
    • in Search change selection from This Mac to "folder name"
    • click Kind
    • select Other and then Size
    • click button OK
    • (solution to my problem is size greater than 1 MB)
  • 8088

    For cleaning my disk of big files, I prefer simply using Grand Perspective:

    cool looking and useful

  • Lake
    • Navigate to the folder in the .
    • Momentarily enter anything in the search field on the toolbar.
      • search field
    • Once you have the search mode active you can delete what you entered to avoid filtering on that text.
    • Click the (+) icon at the right to add a search criteria.
    • Select File size, is greater than, and whatever minimum threshold works for you.
      • Zero (0) is an option, but enough results may make things slow.
    • You may need to right-click (control-click, two-finger click, etc) on the column headers to √ the Size column.

    It will look something like this: files over 1 GB