LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 05-03-2008, 10:15 PM   #1
justmehere
Member
 
Registered: Jul 2005
Distribution: Mandrake 6.1
Posts: 59

Rep: Reputation: 15
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
 
Old 05-03-2008, 10:54 PM   #2
jimbo1708
Member
 
Registered: Jan 2007
Location: Pennsylvania
Distribution: Ubuntu 8.10 Server/9.04 Desktop, openSUSE 11.1
Posts: 154

Rep: Reputation: 31
Quote:
Originally Posted by justmehere View Post
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
 
Old 05-03-2008, 11:20 PM   #3
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
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/ \;

Last edited by jschiwal; 05-06-2008 at 01:08 AM. Reason: fixed ending
 
Old 05-03-2008, 11:23 PM   #4
eggixyz
Member
 
Registered: Apr 2008
Posts: 310

Rep: Reputation: 30
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
 
Old 05-04-2008, 12:11 PM   #5
justmehere
Member
 
Registered: Jul 2005
Distribution: Mandrake 6.1
Posts: 59

Original Poster
Rep: Reputation: 15
Thanks to all replies. I'll try them out.
 
Old 05-04-2008, 02:44 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,004
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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
 
Old 05-04-2008, 03:15 PM   #7
hasanatizaz
Member
 
Registered: Nov 2007
Location: Pakistan
Distribution: Redhat and Debian
Posts: 302
Blog Entries: 1

Rep: Reputation: 34
to execute any command while using find use ' \; '
 
Old 05-04-2008, 07:11 PM   #8
justmehere
Member
 
Registered: Jul 2005
Distribution: Mandrake 6.1
Posts: 59

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jschiwal View Post
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'
 
Old 05-04-2008, 07:28 PM   #9
justmehere
Member
 
Registered: Jul 2005
Distribution: Mandrake 6.1
Posts: 59

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by eggixyz View Post
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.
 
Old 05-04-2008, 07:35 PM   #10
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,004
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Quote:
Originally Posted by justmehere View Post
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
 
Old 05-04-2008, 08:36 PM   #11
justmehere
Member
 
Registered: Jul 2005
Distribution: Mandrake 6.1
Posts: 59

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Tinkster View Post
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.
 
Old 05-05-2008, 12:29 AM   #12
eggixyz
Member
 
Registered: Apr 2008
Posts: 310

Rep: Reputation: 30
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
 
  


Reply


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
Command to copy files/folders but skip bad/corrupt files?? leemoreau Linux - Newbie 2 04-02-2007 03:27 PM
Can't copy files to floppy in GNOME drewblay Linux - Software 4 06-19-2005 06:51 AM
problem copy files to floppy diskette lucent2003 Linux - General 1 01-15-2005 10:29 AM
How do i copy files to a floppy disk?? dsantamassino Linux - Newbie 32 05-30-2003 10:54 PM
find files and copy them to zip drive william47304 Linux - Newbie 1 02-03-2002 04:52 PM


All times are GMT -5. The time now is 09:43 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration