LinuxQuestions.org
Register a domain and help support LQ
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-25-2005, 08:36 AM   #1
dickb
LQ Newbie
 
Registered: Jun 2005
Posts: 15

Rep: Reputation: 0
Talking Copy selected with specified file extensions


I'm a Linux (Knoppix 3.8.3) newbie, but a computer graybie. (old time programmer with gray beard).

I'm working in a terminal window and trying to copy all files with a specified extension from a hard drive ( /dev/hda1 /mnt/hda1 ) to an external USB device (/dev/ubb1 /mnt/ubb1) . I need to preserve the original path information because the same filename may appear in more that one folder on the hard drive, for example readme.doc appears all over the place.

Here's what I am doing now, but it doesn't work right.

su # go to root
mount -o ro /dev/hda1 /mnt/hda1 # mount devices
mount -o rw /dev/ubb1 /mnt/ubb1
cd /mnt/hda1 # go to hard drive

find /mnt/hda1 -name '*.doc' -exec cp {} /mnt/ubb1 \;

This copies SOME of the .doc files but looses the full path informtion.

Everything goes into the root of the hard drive and files with the same filename but differant paths on the hard drive are lost.

I'd appreciate any help on this.
Many Thanks
 
Old 06-25-2005, 09:14 AM   #2
stefan_nicolau
Member
 
Registered: Jun 2005
Location: Canada
Distribution: Debian Etch/Sid, Ubuntu
Posts: 529

Rep: Reputation: 32
Try using rsync.

rsync -r --filter='+ */' --filter='+ *.doc' --filter='- *' /mnt/hda1 /mnt/ubb1

Note: this command will also have the side-effect of copying all directories, even those that do not contain .doc files.

see http://rsync.samba.org/ftp/rsync/rsync.html for more options

Last edited by stefan_nicolau; 06-25-2005 at 09:17 AM.
 
Old 06-25-2005, 10:00 AM   #3
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
Something like this should work:
Code:
$ cd /mnt/hda1
$ find . -name '*.doc' |    <----- list all .doc files recursively
> sed 's/^\.\///' |            <----   remove initial ./
> xargs cp --parents --target-directory=/mnt/ubb1
Hopefully, someone would post a simpler solution.

Last edited by Berhanie; 06-25-2005 at 10:04 AM.
 
Old 06-25-2005, 02:48 PM   #4
dickb
LQ Newbie
 
Registered: Jun 2005
Posts: 15

Original Poster
Rep: Reputation: 0
Talking Simple solution found, maybe

This two step solution works fine. In addition it creates a zip file.
Nota bene: the arguements at the end of the second step are case sensitive.

While it is unlikely that anyone would save a file with the extension dOc, to be absolutely certain I guess I should use all 8 permutations.

1) cd /mnt/hda1/mystuff
2) zip -r /mnt/uba1/backup.zip . -i *.doc *.txt



PS How do I close a Man page ??
 
Old 06-25-2005, 03:43 PM   #5
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
I suppose the canonical solution is:
Code:
$ (cd /mnt/hda1; find . -name '*.doc' | xargs tar cf - ) |
> (cd /mnt/udd1; tar xf - )
You can replace name by iname to make it case insenstive.
Quote:
PS How do I close a Man page ??
That's a pager thing. Try typing the letter "q".

Last edited by Berhanie; 06-25-2005 at 03:45 PM.
 
  


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
Linux File Extensions kompact Linux - Newbie 3 04-18-2005 10:15 AM
Need help with File Extensions Linux nooB 454 Linux - Newbie 3 04-10-2005 06:41 PM
File Extensions!!! rejeK Linux - Software 5 12-20-2004 08:30 PM
File Extensions RpgActioN Slackware 1 09-22-2004 11:20 PM
How to copy a selected content from a .PDF file satimis Linux - General 3 07-03-2003 05:18 AM


All times are GMT -5. The time now is 10:38 AM.

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