Take the 2-minute tour ×

There is a large file sitting on a server in which I only have read permission (not write). I am only interested in the first couple of megabytes in the head of the file and would like to avoid copying the entire large file to my computer. Is it possible to do so?

(note that I cannot use dd or split on the server since this requires write access)

share|improve this question
dd doesn't require write access. –  Let_Me_Be Sep 4 '12 at 15:45
add comment

closed as off topic by Let_Me_Be, martin clayton, Jeremy, gimpf, Lev Levitsky Sep 4 '12 at 22:40


2 Answers

Yes, it is possible via ssh and head:

$ ssh user@server "head -c NUM_BYTES /path/to/file" > file.bin

That will ssh into the server and run the head command on /path/to/file, read off the first NUM_BYTES, and put it locally into a file called file.bin.

share|improve this answer
Use dd when working with binary files. ssh user@server "dd if=file count=10" >file.bin –  Let_Me_Be Sep 4 '12 at 15:51
head works fine too. Do you know a reason why it's not? –  jszakmeister Sep 4 '12 at 15:52
Because head is designed for manipulating text files and therefore will open the file in text mode. –  Let_Me_Be Sep 4 '12 at 15:54
I'd have to inspect source code to be sure, but dd is quite possibly more efficient than head because you can specify block size. A good implementation of head would buffer blocks as well, but it's entirely possible that head could just read a byte at a time, which is much less efficient. @Let_Me_Be Linux/Unix don't distinguish between "text mode" and "binary mode", unlike certain other operating systems. –  twalberg Sep 4 '12 at 15:56
@Let_Me_Be no it doesn't, it uses binary mode. –  jszakmeister Sep 4 '12 at 16:02
show 8 more comments

Actually, I have found that it is possible with dd for example,

dd if=inputfile.txt of=dest/outputfile.txt count=1 bs=1M

share|improve this answer
add comment
