Find Files In A List with known Partial Directories


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Find Files In A List with known Partial Directories
# 1  
Old 09-12-2014
Find Files In A List with known Partial Directories

First I'm new to Linux and have used the find command pretty often but this is where I've hit a snag. I have a file that contains 3500 files that I want to find and then eventually copy to my own directory (these files are all on a shared directory at work atm).

Our work computer are huge and contain large amounts of files and because they are all under numerous directories and sub-directories I wanted to somehow give a loop to make it faster for find to look within the directory I know the file is in (but not necessary which sub-directory). Does that make sense?

Is there an easy way to do that?

Thanks!
# 2  
Old 09-12-2014
Hello Myrona,

The find command is still probably the one you are after. How much information do you know about your targets, or do you just have a list of file names?

Can you tell us which version of Linux you have:-
Code:
uname -a

Differences exist in the various suppliers and versions of Unix (or Linux) so it's important to know what features are available to you so you can get good advice on exploiting them.


At the worst, you could even do:-
Code:
find directory -print | grep -f listfile

.... but there are probably smarters ways available.



Robin
# 3  
Old 09-12-2014
With 3500 files:
Code:
find directory -print | grep -f listfile

listfile is likely to contain some filenames that are subsets of other filenames and could easily have filenames that could appear as a subset of a directory name rather than being the entire name of the final component of a pathname (so the grep could yield false positives).

If the intent is to eventually copy 3500 files from one directory hierarchy to another directory, we also need to know if you intend to put all of those files in a single directory, duplicate the directory structure of the source hierarchy in the destination hierarchy, or create some other directory structure in the destination. (Putting 3500 regular files in a single directory is usually not a good idea.) You could modify listfile to use BREs to look for a / followed by the name and anchor to the end of a line, but if any of your filenames contain BRE special characters (such as period, asterisk,question mark, etc.), you'll have other problems

A simple awk script can read the output of find, match the file names in your list of files against the final component of the pathnames find listed, and print the source pathnames; but I'd need to know more about what destination file hierarchy you want to create before I'd suggest a solution for this project.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Find all files in the current directory excluding hidden files and directories

Find all files in the current directory only excluding hidden directories and files. For the below command, though it's not deleting hidden files.. it is traversing through the hidden directories and listing normal which should be avoided. `find . \( ! -name ".*" -prune \) -mtime +${n_days}... (7 Replies)
Discussion started by: ksailesh1
7 Replies

2. Shell Programming and Scripting

How to list all the files, directories and sub-directories in the current path except one directory?

Can anyone come up with a unix command that lists all the files, directories and sub-directories in the current directory except a folder called log.? Thank you in advance. (7 Replies)
Discussion started by: Manjunath B
7 Replies

3. UNIX for Dummies Questions & Answers

List biggest files (Not Directories)

Hello, can you please help me writing a command that would output the biggest files on my system from biggest to smallest? I want this to print only the files, not the directories. I have tried du -a ~ | sort -nr | head -10 However, this also prints out all the directories - which I do... (8 Replies)
Discussion started by: tonydaniels1980
8 Replies

4. AIX

find command to list all the 777 files and directories owned by root user

Hi I'm logged in to an AIX box now and we need to do an audit on this box. cbssapr01:# pwd / Which command will show all the files and directories owned by root user with permissions as 777 ? (8 Replies)
Discussion started by: newtoaixos
8 Replies

5. UNIX for Dummies Questions & Answers

list directories with more than X files

I want to search a server beginning at /home and list directories with more than X files I found a hack that injects tons of files into a directory How can I search the server recursively and list directories with more than X files? Thank you! like, find /home (directories, that meet the... (5 Replies)
Discussion started by: vanessafan99
5 Replies

6. UNIX for Dummies Questions & Answers

List directories, subs and files

Hi, I try to list all files in a folder, including all the subdirs (and their subdirs) and all files contained in each of these folders. I then print it to a simple txt file. I use ls -R -1 >test.txt This sort of does what I need, yet, the result is something like: It reasonably comes... (53 Replies)
Discussion started by: dakke
53 Replies

7. UNIX for Dummies Questions & Answers

List directories and sub directories recursively excluding files

Hi, Please help me, how to get all the direcotries, its sub directories and its sub directories recursively, need to exclude all the files in the process. I wanted to disply using a unix command all the directories recursively excluding files. I tried 'ls -FR' but that display files as... (3 Replies)
Discussion started by: pointers
3 Replies

8. Shell Programming and Scripting

How to get a list of files in a dir w/o sub-directories?

Hi I am looking for the correct syntax to find all files in the current directory without listing sub-directoris. I was using the following command, but it still returns subdirectoris and files inside them: $ ls -laR | grep -v ^./ Any idea? Thanks PS I am in ksh88 (4 Replies)
Discussion started by: aoussenko
4 Replies

9. UNIX for Dummies Questions & Answers

List directories and files

I want to count how many levels there are under a directory. I repeat level. Also how i count only all the files in a directoy ( all files of all directories of all leves down!) and how can i count only all the directories under a directory (including subdirectories, all levels down) ... (2 Replies)
Discussion started by: psalas
2 Replies

10. Shell Programming and Scripting

Find files in Directories

Hello, We have in a file a list of the path of files from one server. We want to search if these files exist on another server , but the path on this new server isn't the same. We want to use the command "awk" but there isn't the god way. Example: on server 1 in a file : listServer1.txt... (4 Replies)
Discussion started by: steiner
4 Replies
Login or Register to Ask a Question