Questions tagged [head]

head is a program on Unix and Unix-like systems used to display the beginning of a text file or piped data.

Filter by
Sorted by
Tagged with
86 votes
6 answers
84k views

Opposite of tail: all lines except the last n lines

How can I discard the last n lines of a file with a unix command line filter? That would be sort of the opposite of tail: tail discards the first n lines but pipes the rest through, but I want the ...
Dr. Hans-Peter Störr's user avatar
24 votes
4 answers
19k views

Using 'head' or 'tail' on HUGE text file - 19 GB

I have a problem with viewing chunks of a very large text file. This file, approximately 19 GB, is obviously too big to view by any traditional means. I have tried head 1 and tail 1 (head -n 1 ...
nicorellius's user avatar
  • 6,715
22 votes
2 answers
29k views

tail/head all line except X last/first Lines

for example i have this file : cat myfile 1 2 3 4 5 i want to print all lines except first 2 line . output should be like this : tail -n $(( $(wc -l myfile | awk '{print $1}') - 2 )) myfile 3 4 5 ...
network's user avatar
  • 331
14 votes
7 answers
31k views

Creating a large file of random bytes quickly

I want to create a large file ~10G filled with zeros and random values. I have tried using: dd if=/dev/urandom of=10Gfile bs=5G count=10 it creates a file of about 2Gb and exits with a exit status 0....
egeek's user avatar
  • 261
8 votes
3 answers
16k views

How to echo only 1st line from 'curl' command output?

I'm trying to get only first line of the curl command output. (Sorry if this is confusing) Let's say, for an instance, i run simply: # curl http://localhost <!-- This is the hidden line i want to ...
夏期劇場's user avatar
5 votes
1 answer
6k views

How to easily break up a text file into pieces smaller than a threshold?

I have some text files that are 100 to 300 MB in length that I want to view in Emacs, but my Emacs gets into some performance issues opening and traversing such large files. Therefore, I'm looking ...
WilliamKF's user avatar
  • 7,908
5 votes
2 answers
7k views

Stopping after first line of output

I try to do the following in a Bash script: run a command (such as tail -f log_file), wait until a specific output arrives, then stop the command, and go on with the script. I tried the following, ...
petersohn's user avatar
  • 2,672
3 votes
3 answers
2k views

How to grab a random section in the middle of a huge file?

I have a huge log file of around 3.5 GB and would like to sample random sections in the middle of say 10 MB for the purpose of debugging what my application is doing. I could use head or tail ...
WilliamKF's user avatar
  • 7,908
3 votes
1 answer
368 views

Head on very large files

I have 2 very big files (27G and 40G), which are output of dd command on a failing hard drive. I wanted to compare the first bytes to see if the 27G bytes is the begining/substring of the 40G. I ...
Thibault's user avatar
  • 167
3 votes
2 answers
240 views

How to copy head of files to another folder, keeping tree structure?

I have a bunch of huge files (4GB+ each) with the same extension in a directory structure in a network drive, but am only interested in the first few bytes of each, so I'd like to copy them all to my ...
user2986's user avatar
  • 133
3 votes
2 answers
3k views

Unix tool to output first n characters in an UTF-8 encoded file

I want to print the first 1000 characters in an UTF-8 encoded file. I know that the head tool can print the first n bytes of a file, but it may cut a character in the middle so that I get garbled ...
Wu Yongzheng's user avatar
2 votes
1 answer
431 views

What's the best way to view lines X through Y of a large file?

I have a very large text file and I want to view, say, lines 2000 through 2010 (with the line numbers included) I know one sort of roundabout way of getting there: sc -l [file] cat -n [file] | tail -...
Dan Tao's user avatar
  • 1,089
2 votes
1 answer
2k views

How to resolve conflicts when two binaries have the same name

Running OS X (10.9), I have a program called 'HEAD' in /Applications/XAMPP/xamppfiles/bin/, which is related to libwww-perl. The OS also has an unrelated program called 'head' in /usr/bin/ Since the ...
Elliott B's user avatar
  • 1,195
2 votes
1 answer
5k views

How to solve "Broken Pipe" error when using awk with head

I'm getting broken pipe errors from a command that does something like: ls -tr1 /a/path | awk -F '\n' -vpath=/prepend/path/ '{print path$1}' | head -n 50 Essentially I want to list (with absolute ...
Jon's user avatar
  • 21
1 vote
1 answer
1k views

Extracting part of a large SQL dump

Is there a way to chain commands like grep and head together to extract a portion of a file? The problem is that somewhere in my .sql file I have an old data that I need to compare to new data and I ...
Carter's user avatar
  • 113
1 vote
1 answer
36 views

Using head to see up to a character

I have some C source files and a lot of them have a single, 1-line comment at the top that offers a short description of what that program does (I haven't done anything complex enough to warrant a ...
user341814's user avatar
1 vote
1 answer
2k views

head hangs or doesn't terminate on Linux

I'm using, (uname -a says) Linux ip-x-x-x-x 2.6.21.7-2.fc8xen-ec2-v1.0 #1 SMP Tue Sep 1 10:25:30 EDT 2009 x86_64 GNU/Linux. I've got a script, foo.sh with 100 lines of code and when I run head -...
jcarpio's user avatar
  • 111
1 vote
1 answer
2k views

How to grep for line numbers in a binary file?

I'm on Centos 5 Linux and using GNU grep v2.5.1 and looking at a 36GB log file. It is huge and I need to find around a million lines starting from the occurrence of a string 6307459 in the log file ...
WilliamKF's user avatar
  • 7,908
1 vote
1 answer
295 views

Head waits for full stdin before printing

When one runs ls | head head seems to wait for the full output of the piped command before printing to screen. This is undesirable when the command will take a very long time to run, such as when ...
Shadyjames's user avatar
1 vote
1 answer
156 views

get the top urls from the logs

I have a numbers of log files: adsfs.demo.com_2022-07-11-0000-0001_cn.tgz adsfs.demo.com_2022-07-11-0000-0002_cn.tgz adsfs.demo.com_2022-07-11-0000-0003_cn.tgz adsfs.demo.com_2022-07-11-0000-...
244boy's user avatar
  • 615
1 vote
1 answer
2k views

head and cat don't recognize Microsoft Excel text files

I have a large .xls file with 53760 rows and 19 columns. I saved it as Tab Delimited Text in order to pre-process it through command line tools and load it into R later. However, when I run head ...
Marcus Nunes's user avatar
1 vote
3 answers
5k views

zcat | head : write error from large gz file

I was trying zcat to get only the first 1M lines of a compressed .gzip file into a new one. However, I get the following error: $ zcat path/to/R2.fq.gz | head -100 >R2.fqtest head: write error: ...
Carmen Sandoval's user avatar
0 votes
1 answer
181 views

Read a Section of Lines from a File in Linux

I'm trying to export lines 100 to 1,000,100 from a file with 62 million lines. So far I've found this command: head -1100000 input > output But head does not take an offset option. Thoughts?
Kirk Ouimet's user avatar
  • 2,725
0 votes
2 answers
381 views

How to get SHA1 of first 4096 bytes of an mp4 file or stream?

I am trying to use command line tools to match the hash value that Plex.app computes for movie files (apparently, it's an SHA1 hash of the first block (4k) of a movie instead of the entire movie). I ...
John's user avatar
  • 415
0 votes
1 answer
320 views

Linux head/tail commands' man page does not show the '-LINES' argument

I have just read in a book that the command head -LINES displays the first LINES lines of a file. However, head's man page does not seem to reveal this is a legit argument. I'd like to know what I am ...
PhantomR's user avatar
  • 139
0 votes
1 answer
1k views

How can I detect/remove special characters from this short text file?

This is the contents of a short text file created by an AppleScript written by someone else: Search time: Sunday April 28, 2019 at 07:21:07 Search complete. Nothing found. But, when I use cat I get ...
Buadhai's user avatar
  • 111
0 votes
0 answers
22 views

Mapping ddrescue and data from a particular head on a hdd

I'd like to clone data from a particular head of a HDD. Can I do a ddrescue and then divide the rescue image by the number of heads to get multiple images, each with data from one head/surface? ...
bmcws's user avatar
  • 1
0 votes
1 answer
141 views

how to output only a specific known line number using cat or head/tail

I know how to use head or tail to output a certain number of lines, but how do I output only a specific line number(s)? Something like: head --only-line=73 <file>
Oliver Williams's user avatar
0 votes
1 answer
177 views

`openssl digest | head -c 10` gives strange results

I'm using salted hashes of some memorable words as login/pass for anonymous accounts and just now I've noticed that sometimes I get no result for my method and then I've discovered that it was not ...
dm33tri's user avatar
  • 23
0 votes
1 answer
69 views

Command Line Number Line Not In Sync

I'm playing around with the command line. For some reason when I try to grab lines 439 - 445 the output I am getting is lines 375 - 381 instead. I use the tail command to jump to line 439 then use the ...
Dre's user avatar
  • 3
0 votes
1 answer
96 views

Automatic head in ms-word

I’m creating a template in word and would like to include a text field in the cover for the title, something like "Document Title", that will be replaced by the user with the real title the want to ...
tanaan's user avatar
  • 1
0 votes
0 answers
584 views

Copy huge file skipping first line using dd in Linux

I was trying to copy the content of a huge file (10GB) to another skipping the first line (as in head -n1). I tried multiple ways of head, tail, awk and sed. Settled on using tail -n+2 > ./xab.1 ...
Jimson James's user avatar