Scan first 512 bytes for strings with gnu strings command

2

I'm trying to use the GNU strings tool for a clean way to get all strings more then 5 chars in a compiled file but only in the first 512 bytes.

strings compiledfile -n 5

With the above command you scan the complete file but does someone have a nice bash solution to only scan the first 512 bytes?

Already a big thanks.

Roel

Posted 2017-06-22T12:16:13.957

Reputation: 23

Answers

2

(untested)

head -c 512 | strings -n 5

Nifle

Posted 2017-06-22T12:16:13.957

Reputation: 31 337

Thanks very much, I was thinking of using head but didn't know yet for sure. good 1. – Roel – 2017-06-22T12:37:38.890

1

This should go a long way:

dd if=compiledfile bs=512 count=1 | strings -n 5

dd will only copy the first 512 bytes to to STDOUT, which can then be parsed by strings.

mtak

Posted 2017-06-22T12:16:13.957

Reputation: 11 805

So... I tried this. And it actually didn't work. First of all at the end you get the extra information: 1+0 records in 1+0 records out 512 bytes (512 B) copied, 3.2017e-05 s, 16.0 MB/s and after that the piping toward strings made it not recognise the strings inside the first bytes only those last 3 lines. – Roel – 2017-06-22T12:35:59.080