INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

find one of many files in multiple directories from a list

find one of many files in multiple directories from a list

find one of many files in multiple directories from a list

(OP)
Hi,

I have multiple directories with multiple duplicates of files scattered throughout. I am only interested in files of a certain file extension (e.g "*.bar").
I have a unique list of the duplicated files of that extension in my location - this is my "input_list.txt":

abc123.bar
abc456.bar
def123.bar
xxx999.bar


I know that the file "abc123.bar" exists in multiple places underneath a certain point on my file system, saved into different directories. I also know that the files with duplicate file names will always be duplicated files (exactly the same) - so I do NOT need to do any sort of chksum or date/file size comparison on the files. As long as the name is the same, I want ONE copy of it, from any of the directories it is stored in.

** All I want is one copy of each unique file in my "input_list.txt" copied into one directory. **

Can you suggest an efficient way to do this? Ideally I'd like a script that takes the "input_list.txt" as input, the top level directory path to start the search from and the output directory to copy the files to.
An indication of where the script is up to would be useful, like this:

23-06-2014 13:00  Copying file 1 of 132: abc123.bar ...
23-06-2014 13:09  Copying file 2 of 132: abc456.bar ...
23-06-2014 13:13  Copying file 3 of 132: def123.bar ...
23-06-2014 13:15  Copying file 4 of 132: xxx999.bar ... 

RE: find one of many files in multiple directories from a list

Maybe something like this?

CODE

# Caution: Untested code

find /path/to/barfiles -name '*.bar' -print | grep -f input_list.txt | xargs -n 1 cp {} /target/dir 

It may copy the same file more than once if it's in multiple directories, but you will end up with only one copy since there is a single target directory.

RE: find one of many files in multiple directories from a list

Hi there,

case you really want only 1 file on the whole system maybe "mv" would be the better choice than "cp" ... smile

Regards,
Thomas

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close