LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Learn the DD command (https://www.linuxquestions.org/questions/linux-newbie-8/learn-the-dd-command-362506/)

carrot_ 06-18-2016 08:48 PM

Great tutorial! However, you should make it shorter, in my opinion.

JZL240I-U 06-20-2016 01:02 AM

AFAIR the OP intended to write a (hand)-book on dd. Maybe he could tell us his present view?

AwesomeMachine 06-23-2016 11:49 PM

If anyone wants a shorter one he/she can take what they want out of my op--thinly paraphrased of course--and write a shorter one. I guess I wonder, what do you want me to remove to make it shorter?

JZL240I-U 06-24-2016 01:42 AM

Ah, well, that leaves out the clarifications and additional information you and others added over time. So no book. Pity, but thanks anyway for this thread

AwesomeMachine 06-30-2016 01:05 PM

I am, among other things, a professional writer. I inquired with several publishers about the possibility of writing a linux book. There were no takers, because everything is online. And there isn't much anyone can do about the length of the discussion thread.

awesomereqs 09-01-2016 08:57 AM

dd
 
Hello, and thank you for halping me out a few times over the years. DD is awesome, and has helped me out loads.

Now, I want to ask about something specific with DD, and that is how to recover a text file which amazingly no undelete program seems to offer, by way of searching the contents for a string, and then saving, say 200kb before it, and 100 kb after it, into one file, on a different file system.

Something like this might be of use to save an email from the black hole of <whatever> or even an npp user from the occaisional freak behaviour of notepadplusplus.

So, I know a string "apply-online-for-student-finance" which was part of the file which I last wrote, and it had other useful stuff too, of which I cannot remember all, and I got as far as
dd if=/dev/sda1 | strings | grep 'apply-online-for-student-finance'

but got lost in all the whirlygig of stuff and couldn't complete.
is it possible someone can help me in my quest.

Thank you in advance

jpollard 09-01-2016 07:52 PM

Well.... this is totally off topic from dd so likely you should start another thread...

I used to do this (with MUCH SMALLER disks/partitions that is common now) by using an editor and opening the disk partition (read only, and in binary mode -since it is text you are looking for this may be optional, AND with no swap file: vim -r -b -n /dev/whatever-partition). Then search for the string. When found you can use the editor to look before/after the string, and write only the part you want.

I'm not sure how vim does it now, because it has ben over 20 years since I did this with vi.

BTW, one problem this has is that files now can be more fragmented. Thus you may find the string - but that only locates one block (4k) of the file you want. To find other parts of the file you will have to identify other strings...

rknichols 09-01-2016 10:42 PM

You can use hexedit to search (either in ASCII or in hex) and make modifications, with no limit on partition size. The modifications are limited to simple overwriting (no insertions or deletions). The modifications are kept in memory until you exit and choose to write out the changes, so the number of modifications is limited by the available memory.

(Sorry -- only read the immediately preceding post.)

themanwhowas 09-02-2016 09:36 PM

I used to use xxd and grep. Or foremost...

awesomereqs 09-06-2016 04:45 AM

Thanks for all your answers, and the other tools you have given which could possibly also solve the problem, although I would prefer to stick with DD and am as yet no closer to solving this little script.

jpollard 09-06-2016 05:23 AM

dd is a very good tool - but all it does is copy data.

You asked for search. dd doesn't search.

The next problem was that you wanted to extract a 200k before and after a given string. Files are not stored that way. Each block MAY be stored separate from other blocks of the same file. Some filesystems will attempt to keep things together (ext4 does), it is not mandatory that it do so. Thus the most you can reliably get is the 4k block that contains the string. Note, the string itself may be split at a block boundary, and thus a search may not find it as searches expect things to be contiguous.

AwesomeMachine 10-05-2016 10:29 PM

You can use the strings command to do searches. You can also use dd with grep.

AwesomeMachine 10-05-2016 10:41 PM

strings (verb form) the whole drive
 
Quote:

Originally Posted by awesomereqs (Post 5599247)
I got as far as
dd if=/dev/sda1 | strings | grep 'apply-online-for-student-finance'

Just try $ strings -n 8 /dev/sda | grep 'apply\-online\-for\-student\-finance'

One problem with dd is that it fully processes every bit. That's slow. But if you really need every bit it's good. If you don't there are other tools.

I'm not sure if hexdump + grep works, because you have to search multiple lines in the ascii pane, and I'm not positive -B and -A switches search before and after, or just display before and after.

Arshar 11-09-2017 02:55 PM

Thank you !

AwesomeMachine 12-08-2017 11:45 PM

Clarification
 
Quote:

Originally Posted by TobiSGD (Post 4773135)
Copying an ISO image to a disk using dd is only possible if the ISO image is a hybrid-ISO.

You can always copy an ISO to a HDD. But if you want the HDD to boot, it has to be a hybrid ISO.


All times are GMT -5. The time now is 09:16 AM.