Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .