LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 02-15-2005, 10:53 AM   #1
LancerNZ
Member
 
Registered: Oct 2004
Location: New Zealand
Distribution: Fedora Core 2
Posts: 40

Rep: Reputation: 15
Question Complex cp : only *.jpg files while excluding DIRs


The school I'm teaching at has not yet put up their network so all computers are completely separate. As the teacher, I'm trying to transfer newly made files from the /home DIRS across all computers.

e.g: if Sarah made a new /home/sarahb/my_picture.jpg then I want to put this onto floppy and transfer (preserving permissions etc) onto the other computers.

Something like...

\cp -puRf /home/*/*.jpg /mnt/floppy/

Then once the files are transferred, I would simply place the floppy with combined collected files into each computer, and cp the contents back over the /home dir in each to distribute all files throughout.

However, here are the caveats...

1) I want to mainatain the subdir trees.
2) I ONLY want to do *.jpg files
3) At the same time I want to EXCLUDE the /home/teacher/ directory.

As I originally clones the drives via IDE cable (which took a long time) permissions etc for /home accounts are identical.

I'm thinking that two shell scripts should do this, and could reside on the floppy. One to suck the needed files (place floppy in computer drive and hit "/mnt/floppy/get_student_jpg.sh", the other to redistribute them (place floppy indrive and hit "copy_to_home.sh")

Any ideas?
 
Old 02-15-2005, 12:27 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 58
You could do it using find - perhaps something like this:
Code:
cd /home
find ./ -name "*.jpg" \! -regex "./teacher.*" -exec mkdir /mnt/floppy/\`dirname {}\`\\\;cp {} /mnt/floppy/ \;
Copying them back should just be a standard recursive copy:
cp -r /mnt/floppy/* /home/

Last edited by david_ross; 02-15-2005 at 12:29 PM.
 
Old 02-16-2005, 02:58 AM   #3
LancerNZ
Member
 
Registered: Oct 2004
Location: New Zealand
Distribution: Fedora Core 2
Posts: 40

Original Poster
Rep: Reputation: 15
Thanks for the reply.

However - your code (which I carefully copied and pasted from the forum) did not work. I got a few "cannot create ./studentname/somedir/anotherdir/file.jpg file already exists" errors and an empty directory called `dirname manifesting onto /mnt/floppy.

Could the forum be have added some of those //'s to rhw code? I don't understand -regex options well enough to be able to sort this one in good time for tomorrow's lessons (it's late and I'm just back from parent meetings).
 
Old 02-16-2005, 03:12 AM   #4
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: Nantes (France)
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
Source:
Code:
find /home -type d -regex "/home/teacher" -prune -o \( -iname "*.jpg" -o -iname "*.jpeg" \) -print | xargs tar cjf /mnt/floppy/backup.tbz
Dest:
Code:
cd / && tar xjpf /mnt/floppy/backup.tbz
I'm not sure the floppy will be big enough every time, though.
Besides, with pictures, it might be, that bzipping the tar actually makes it bigger instead of smaller. In that case, remove the "j" from each tar command, and replace the ".tbz" extention with a simple ".tar".

Yves.
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
remove files excluding those with specified extensions Melsync Linux - General 15 10-04-2005 01:42 PM
invisible files and dirs karmine Slackware - Installation 8 12-26-2004 03:05 PM
ls, dirs first, files later TroelsSmit Linux - Newbie 4 05-31-2004 11:47 AM
Excluding directories from zip files jonathanztaub Linux - General 1 05-17-2004 02:17 AM
tar and excluding files murshed Linux - Newbie 7 03-15-2003 02:32 PM


All times are GMT -5. The time now is 11:01 AM.

Main Menu
 
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
Open Source Consulting | Domain Registration