LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-18-2016, 09:48 PM   #841
carrot_
LQ Newbie
 
Registered: Jun 2016
Posts: 1

Rep: Reputation: Disabled

Great tutorial! However, you should make it shorter, in my opinion.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 06-20-2016, 02:02 AM   #842
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE 42.1_64+Tumbleweed-KDE, Mint 17.3
Posts: 3,957

Rep: Reputation: Disabled
AFAIR the OP intended to write a (hand)-book on dd. Maybe he could tell us his present view?
 
Old 06-24-2016, 12:49 AM   #843
AwesomeMachine
Senior Member
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora
Posts: 1,842

Original Poster
Rep: Reputation: 260Reputation: 260Reputation: 260
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?
 
Old 06-24-2016, 02:42 AM   #844
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE 42.1_64+Tumbleweed-KDE, Mint 17.3
Posts: 3,957

Rep: Reputation: Disabled
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
 
Old 06-30-2016, 02:05 PM   #845
AwesomeMachine
Senior Member
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora
Posts: 1,842

Original Poster
Rep: Reputation: 260Reputation: 260Reputation: 260
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.
 
Old 09-01-2016, 09:57 AM   #846
awesomereqs
LQ Newbie
 
Registered: Sep 2016
Posts: 3

Rep: Reputation: Disabled
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
 
Old 09-01-2016, 08:52 PM   #847
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
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...

Last edited by jpollard; 09-01-2016 at 09:10 PM.
 
1 members found this post helpful.
Old 09-01-2016, 11:42 PM   #848
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 2,967

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
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.)

Last edited by rknichols; 09-01-2016 at 11:52 PM. Reason: Sorry, ...
 
Old 09-02-2016, 10:36 PM   #849
themanwhowas
Member
 
Registered: Nov 2005
Distribution: CentOS 5, Fedora 23
Posts: 216

Rep: Reputation: 29
I used to use xxd and grep. Or foremost...
 
Old 09-06-2016, 05:45 AM   #850
awesomereqs
LQ Newbie
 
Registered: Sep 2016
Posts: 3

Rep: Reputation: Disabled
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.
 
Old 09-06-2016, 06:23 AM   #851
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
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.
 
2 members found this post helpful.
Old 10-05-2016, 11:29 PM   #852
AwesomeMachine
Senior Member
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora
Posts: 1,842

Original Poster
Rep: Reputation: 260Reputation: 260Reputation: 260
You can use the strings command to do searches. You can also use dd with grep.
 
Old 10-05-2016, 11:41 PM   #853
AwesomeMachine
Senior Member
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora
Posts: 1,842

Original Poster
Rep: Reputation: 260Reputation: 260Reputation: 260
Cool strings (verb form) the whole drive

Quote:
Originally Posted by awesomereqs View Post
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.
 
  


Reply

Tags
backup, best, clonezilla, cloning, command, data, dd, disk, drive, duplicate, erase, explanation, formatting, ghost, hard, image, iso, memory, ping, popular, recover, recovery, rescue, search, security, stick, upgrade, usb, wipe


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Learn The DD command AwesomeMachine Linux - Newbie 17 08-17-2006 05:22 AM
The best way to learn? iz3r Programming 7 02-07-2005 12:00 AM
Best way to learn Linux from the command line patpawlowski Linux - General 2 03-01-2004 04:37 PM
I want to learn C. KptnKrill Programming 14 12-18-2003 02:03 PM
Best way to learn.... InEeDhElPlInUx Linux - Newbie 5 10-11-2003 02:02 AM


All times are GMT -5. The time now is 04:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration