LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 04-10-2017, 12:23 PM   #1
atjurhs
Member
 
Registered: Aug 2012
Posts: 258

Rep: Reputation: Disabled
recursively copy specific files using a list


hi guys,

I need to copy a set of specific files that exist in a directory structure with sub-directories. my initial attempt was to use

Code:
find . -name "*.h5" -exec cp {} ~/home/tmp ";"
this copied all of files that are of type .h5 but some of these .h5 files are really really big BIG, on the order of several gigs, and i don't need/want them.

so i need to find a way to copy specific files that all end in .h5 but also have different names such as:

Code:
.123_yellow.h5
.123_yellow.csv
123_Chevrolet.h5
abcdefg.log
abc_red.log
abc_red.h5
windows_123.h5
     /subdirectory
          .green.h5
          .purple.h5
          mac_ford.h5
          linux_white.h5
where in this directory structure i only want to keep those files with a "color" as part their name. so i would first make a separate file that has a listing of the files i need:


Code:
.123_yellow.h5
.green.h5
.purple.h5
abc_red.h5
linux_white.h5
then execute a command that reads the list and copies only the files i need and that are in the list to the ~/home/tmp

is this doable or way to involved for an awk or bash or python, btw i don't know python or perl

can you help or not?

thanks!!!

Todd

Last edited by atjurhs; 04-10-2017 at 12:58 PM.
 
Old 04-10-2017, 12:37 PM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 6,903
Blog Entries: 3

Rep: Reputation: 3585Reputation: 3585Reputation: 3585Reputation: 3585Reputation: 3585Reputation: 3585Reputation: 3585Reputation: 3585Reputation: 3585Reputation: 3585Reputation: 3585
Since you've started with find you can continue with that just as well as with other options. Options in find are connected by a logical AND unless specified otherwise. If you use a logical OR then you'll need to group parts using parenthesis. And to keep the shell from interpreting the parenthesis, they need to be escaped or quoted:

Code:
find . -name '*.h5' \( -name '*red*' -o -name '*green*' \) -print
When you have what you want, swap out the -print for -exec as you had.
 
Old 04-10-2017, 02:09 PM   #3
atjurhs
Member
 
Registered: Aug 2012
Posts: 258

Original Poster
Rep: Reputation: Disabled
cool!

that does look much simpler than i had thought this do be!

i have a long list of "color" files but this solution is easy and brute force (i like brute force) will get it done

Last edited by atjurhs; 04-10-2017 at 03:01 PM.
 
Old 04-10-2017, 02:28 PM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,788
Blog Entries: 13

Rep: Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831
First, you could move them versus copy them.

Second, that first option does seem unlikely, you may have a database of files which you wish to retain and then reference. Therefore my way of thinking would be that you would be creating a custom new file or set of files and perhaps taking that off system? Thus it might be going to a temporarily mounted file system like a thumb stick? Otherwise if you just need the reference names as part of your find command, then you could output just the list of found files and their locations and keep that versus copy the files all the time. All depends how much, how often, and how large the sub-selected files happen to be.
 
Old 04-10-2017, 02:59 PM   #5
atjurhs
Member
 
Registered: Aug 2012
Posts: 258

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
First, you could move them versus copy them.

Second, that first option does seem unlikely, you may have a database of files which you wish to retain and then reference. Therefore my way of thinking would be that you would be creating a custom new file or set of files and perhaps taking that off system? Thus it might be going to a temporarily mounted file system like a thumb stick? Otherwise if you just need the reference names as part of your find command, then you could output just the list of found files and their locations and keep that versus copy the files all the time. All depends how much, how often, and how large the sub-selected files happen to be.
thanks for the thought!

but i can not do a mv as there are other users that also need access to the files

Last edited by atjurhs; 04-10-2017 at 03:06 PM.
 
Old 04-10-2017, 04:49 PM   #6
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,173

Rep: Reputation: 2647Reputation: 2647Reputation: 2647Reputation: 2647Reputation: 2647Reputation: 2647Reputation: 2647Reputation: 2647Reputation: 2647Reputation: 2647Reputation: 2647
If the concern is the size of the files, you could consider using the -size option with find.
Code:
find . -name '*.h5' -size -<your size specification> -print
 
Old 04-10-2017, 07:15 PM   #7
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 20,841

Rep: Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008
Do you need to copy them at all - would a link suffice ?.
 
  


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
command to copy mp3 files recursively ejames82 Linux - General 8 11-15-2016 04:34 PM
Site Hacked - Deleting Specific Line from files recursively? CrewXp Linux - Security 6 04-27-2011 07:23 AM
How to list contents of all files recursively spoovy Linux - General 8 01-24-2011 10:19 AM
How to list all files recursively, in a non-broken list? nyle Linux - Newbie 1 12-16-2008 10:52 PM
list recursively files with for xeon123 Programming 6 04-04-2007 03:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:06 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
Open Source Consulting | Domain Registration