LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 09-11-2007, 03:43 PM   #1
Inner City Blues
LQ Newbie
 
Registered: Sep 2007
Posts: 1

Rep: Reputation: 0
Copying File Hierarchy with Specific Filetype


Hello,

I'm trying to make a script where I move data from an archive and copy it to a new directory where it can be modified. The problem is the archive also has many extraneous files that I will not be using, so I don't want those copied over.

Right now I have things set up as follows:
Code:
#!/bin/sh
cd /modify_folder/
fileName="folder_list.txt"
cat $fileName |   \
while read line do
cd /modify_folder/ mkdir $line cd /archive_folder/$line cp -R Contents*/ /modify_folder/$line
done
So this code will go to my modify_folder and open a text file with a list of folders (markers). It will then use this list of markers and iterate through the archive and copy the Contents folder (and all its subfolders) to the modify_folder, so in the end you'll have:

/modify_folder/marker_1/Contents/
/archive_folder/marker_1/Contents/

Both with the same data. Without having to script the removal of the extraneous files, is there a way to restrict the filetypes that are copied? That is let's say we have zip files and txt files, and I just want the zip files copied. At the same time I want to maintain the file hierarchy. I hope that's clear, any suggestions? Thanks.
 
Old 09-11-2007, 05:00 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Hi, and welcome to LQ!

And here (untested) a minor modification of your script:

Code:
#!/bin/sh
cd /modify_folder/
fileName="folder_list.txt"
cat $fileName |   \
while read line do
  cd /modify_folder/ mkdir $line 
  cd /archive_folder/$line 
  for i in Content*
  do
    find $i -name "*zip" -exec cp --parents {}  /modify_folder/$line/. 
  done
done
Hope I understood your request properly :}


Cheers,
Tink
 
Old 09-11-2007, 05:24 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,332
Blog Entries: 55

Rep: Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533
How about a 'find /some/directory -iname \*.zip -o -iname \*.txt | cpio -pavd /some/other/dir' oneliner?
 
  


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
Using WGET to download specific filetype itz2000 Linux - Newbie 3 02-03-2007 05:49 AM
help on linux file system hierarchy revoked Linux - Newbie 6 07-22-2006 11:06 AM
where to store mp3 in file hierarchy leopardb Linux - Newbie 6 07-05-2005 10:40 AM
Prevent a specific filetype from being created? Phaethar Linux - Security 0 02-17-2005 12:49 PM
Copying files from a specific date dman65 Linux - Software 3 09-22-2003 11:16 AM


All times are GMT -5. The time now is 05:43 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