LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to find files and copy the found files to the floppy in one command (http://www.linuxquestions.org/questions/linux-newbie-8/how-to-find-files-and-copy-the-found-files-to-the-floppy-in-one-command-639706/)

justmehere 05-03-2008 09:15 PM

How to find files and copy the found files to the floppy in one command
 
I am trying to find all files which are called index.* and at the same time want to copy the found files to the floppy drive ?

To find I typed in find / -name index* but how can I copy the same files to the floppy drive ?

Thanks

jimbo1708 05-03-2008 09:54 PM

Quote:

Originally Posted by justmehere (Post 3141684)
I am trying to find all files which are called index.* and at the same time want to copy the found files to the floppy drive ?

To find I typed in find / -name index* but how can I copy the same files to the floppy drive ?

Thanks

Hello,

why not try some variation of the following command. I don't use find, but rather locate.

Code:

root@mybox:/# for i in `locate index.`; do cp $i /media/destination/; done;
Please test and research before deploying, but this should be a good starting point. If you find that files are missing, run 'updatedb' as root to repopulate the locate database.

- Jim

jschiwal 05-03-2008 10:20 PM

You need to put the name inside double quotes:

Using / as the base directory isn't a good idea because you will be searching the entire system. You should have a better idea where the file would be.

find /usr -name "index*" -exec cp '{}' /mnt/floppy/ \;

eggixyz 05-03-2008 10:23 PM

Hey There,

You can also use the -exec flag for your find command, so it would look like this:

find / -name ".index*" -exec cp {} /dev/fd/ \;

Assuming /dev/fd is your floppy. As per the other suggestion, please test beforehand, just in case. That's always good advice :)

Best wishes,

Mike

justmehere 05-04-2008 11:11 AM

Thanks to all replies. I'll try them out.

Tinkster 05-04-2008 01:44 PM

The problem with that approach "cp {} /mnt/fd" is that if two
files happen to have the same name you'll only keep the version
it found on HDD last on floppy.


To eggixyz:

You *don't* copy to the raw device.... try the mounted device.



Cheers,
Tink

hasanatizaz 05-04-2008 02:15 PM

to execute any command while using find use ' \; '

justmehere 05-04-2008 06:11 PM

Quote:

Originally Posted by jschiwal (Post 3141738)
You need to put the name inside double quotes:

Using / as the base directory isn't a good idea because you will be searching the entire system. You should have a better idea where the file would be.

find /usr -name "index*" -exec cp '{}' /mnt/floppy/

Many thanks for the above example but I am getting the error when running the above exact command:

find: missing argument to '-exec'

justmehere 05-04-2008 06:28 PM

Quote:

Originally Posted by eggixyz (Post 3141739)
Hey There,

You can also use the -exec flag for your find command, so it would look like this:

find / -name ".index*" -exec cp {} /dev/fd/ \;

Assuming /dev/fd is your floppy. As per the other suggestion, please test beforehand, just in case. That's always good advice :)

Best wishes,

Mike

Thanks for the above reply. This one worked for me. I might have been doing something wrong on the other suggesions.

Tinkster 05-04-2008 06:35 PM

Quote:

Originally Posted by justmehere (Post 3142691)
Thanks for the above reply. This one worked for me. I might have been doing something wrong on the other suggesions.

The copy may have worked - but is the data on the floppy?


Cheers,
Tink

justmehere 05-04-2008 07:36 PM

Quote:

Originally Posted by Tinkster (Post 3142696)
The copy may have worked - but is the data on the floppy?


Cheers,
Tink

Yes the files were copied to the floppy and they are valid files. Not sure may have missed the odd index file. But overall its working.

eggixyz 05-04-2008 11:29 PM

Hey There,

Glad that's working out for you :)

To clarify, Tinkster is correct that you should mount the floppy and then write to that file. I just shot that out there quickly.

The reason for this is that, if /dev/fd doesn't have a floppy mounted, your command won't fail. It's better practice to mount the floppy on /dev/fd and then do you cp to that mountpoint.

Thanks for heads-up, Tinkster. I often type first and ask questions later ;)

Best wishes,

Mike


All times are GMT -5. The time now is 01:47 PM.