Stack Exchange Network
Stack Exchange network consists of 181 Q&A communities including
Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchange
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this community
Anybody can ask a question
The best answers are voted up and rise to the top
6 years, 1 month ago
This question already has answers here:
6 years ago.
I want to get the first 20 or so characters from a number of files.
I've seen examples using cut but they all seem to get the first 20 characters of each line in the file, while I only want the first characters in the file itself (ie. from the first line), nothing more.
Is there a simple way to do this?
Feb 20, 2017 at 18:16
1,007 3 3 gold badges 14 14 silver badges 27 27 bronze badges
Complete command would be:
head -c 20 yourFile.txt
103 4 4 bronze badges
Feb 20, 2017 at 18:28
Philip Kirkbride Philip Kirkbride
9,546 24 24 gold badges 91 91 silver badges 162 162 bronze badges
Didn't realize the -c option for
head was non portable. You can use
dd to output the first 20 bytes like so:
dd if=/path/to/infile of=/path/to/outfile bs=20 count=1
You can omit the
of=/path/to/outfile part if you want your result to stdout.
Feb 20, 2017 at 18:44
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our
Accept all cookies
Necessary cookies only
headassumes 1 byte = 1 character.
-coption is a non-portable extension.
cut) be the tool used. OP simply noted that they had seen examples using