Linux - NewbieThis 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!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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.
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.
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...
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 10:52 PM.
Reason: Sorry, ...
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.
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.