Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

If I do this:

grep -a -n 'test' /dev/sdb10

It will search on the device sdb10 at binary level for a string 'test'. I can see the output of 'n' option, but what does it represent? Is the device treated as a single file?

My objective is to pinpoint the location of a file on the device so I can 'dd' a section of the drive.

share|improve this question
    
Maybe 'n' is the line number in term of 'line feed' characters? –  code-gijoe Mar 12 '13 at 18:45

1 Answer 1

up vote 3 down vote accepted

The -a switch (--text) does treat binary files as if they were text files and the device file /dev/sdb10 is always treated as if it were an actual file, but the -n switch (--line-number) only prints line numbers, which is rather useless in this case. The -b switch (--byte-offset) will help you find the location of the string.

To avoid echoing a lot of non-printable characters as well, you can use it in combination with the -o switch (--only-matching).

Example:

sudo grep -abo test /dev/sdb10
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.