Download your favorite Linux distribution at LQ ISO.
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 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


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:
cd /modify_folder/
cat $fileName |   \
while read line do
cd /modify_folder/ mkdir $line cd /archive_folder/$line cp -R Contents*/ /modify_folder/$line
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:


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
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:

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

Old 09-11-2007, 05:24 PM   #3
Registered: May 2001
Posts: 29,361
Blog Entries: 55

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


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 > Forums > Linux Forums > Linux - Newbie

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