Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 06-25-2005, 07:36 AM   #1
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, 08:14 AM   #2
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 for more options

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

Rep: Reputation: 165Reputation: 165
Something like this should work:
$ 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 09:04 AM.
Old 06-25-2005, 01:48 PM   #4
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/ . -i *.doc *.txt

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

Rep: Reputation: 165Reputation: 165
I suppose the canonical solution is:
$ (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.
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 02:45 PM.


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

All times are GMT -5. The time now is 06:07 PM.

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