finding files in unix and excluding certain folders


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers finding files in unix and excluding certain folders
# 1  
Old 09-13-2011
finding files in unix and excluding certain folders

hi good day
I am using redhat linux.
Is there a better utility than the 'find' command to search for files
I am trying to search through and enitre directory such as /repos for a files that have 'UAP' in it. However there are some '.step' folders littered throughout the /repos folder at varying levels, that I want to exclude from the search, so that the search will be faster. Is there a way to do this, also is there a way to limit the search to just files created with my user account id. example

find /repos BUT -exclude folders with '.step' type f -iname '*UAP* PLUS -userid john

Is there some way to achieve this. I am mainly looking to increase speed since there are a large number of files.

thanks
# 2  
Old 09-13-2011
Option "find -user xxx" will limit it to your files, but still it will look everywhere. Dirs contain just entry names and inode numbers, so it has to go through all the inodes to do any such filtering.

Moving all those dirs to another device and replacing the original entry names with symlinks to them means without -follow it will ignore them.

Sometimes parallel processing can speed up the find, with a find in each subtree.
# 3  
Old 09-13-2011
To case-insensitively search under /repo for filenames matching *UAP* that are owned by john while not descending into any portion of the hiearchy under a .step directory:
Code:
find /repo \( -type f -user john -o -type d -name .step -prune \) -iname '*UAP*

The logic depends on the fact that a filename exactly matching .step cannot possibly match *UAP*. If this were not the case, another type -f could be added after -prune.

Regards,
Alister
# 4  
Old 09-13-2011
Wow that works, thanks much.
While I was waiting I experimented with the ls command.

ls -lR | grep UAP

this command seemed to work also. It ignored the folders with the dot in front it.
What do you think?

Also is there a way with that find command (or the ls command) you showed to let the command search through the tree but instead of making it ignore the .step folder, can you write an expression that will only look in folders that had a particular name such as com_station2 no matter where such a folder exist, lets say there is a /repo/fid2/com_station2/ and /rpos/fid3/com_station2/. So that it ignores all other folders except if there is a com_station2 in the path name. And it will still search for files with *UAP* in it.

Thanks alot
# 5  
Old 09-13-2011
Yeah. ls won't include dotfiles unless the -a option is given. If that ls|grep pipeline meets your needs, go for it.

As for your modified request:
Code:
find /repo -type -iname '*UAP*' -path '*/com_station2/*'

Regards,
Alister
# 6  
Old 09-13-2011
great thanks very much alister. I'll be able to find any file from now on.
# 7  
Old 09-13-2011
Quote:
Originally Posted by johnstrong
Wow that works, thanks much.
While I was waiting I experimented with the ls command.

ls -lR | grep UAP

this command seemed to work also. It ignored the folders with the dot in front it.
What do you think?
  • It finds files and folders by any user, not just 'john'.
  • It ignores any folder or file beginning with ., not just folders named .step
  • It matches UAP anywhere on the line, allowing potential false matches from user and group names with UAP in them
  • It prints headers and titles and totals which would make it difficult to use this output in a script.
  • It prints relative paths, not absolute ones, making it more difficult again to use the output in a script.

If it fits your needs it fits your needs, but it really doesn't do what you asked for at all.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding duplicates in a file excluding specific pattern

I have unix file like below >newuser newuser <hello hello newone I want to find the unique values in the file(excluding <,>),so that the out put should be >newuser <hello newone can any body tell me what is command to get this new file. (7 Replies)
Discussion started by: shiva2985
7 Replies

2. UNIX for Advanced & Expert Users

Copying excluding some files and folders

I have a main folder. Inside that i have many(50) subfolders. In each subfolder, there are a no of large files(500 files ) present. I want to do copy operation for some files from some of the subfolders to /usr/tmp. I have the list of the subfolders and list of of files which i dont want to... (4 Replies)
Discussion started by: millan
4 Replies

3. UNIX for Dummies Questions & Answers

Finding new file, but excluding directory..

hi, I need to find files that have been created less than 3 days ago. However, I need to only search specific directories. I've searched about the net and found some useful commands such as : find . -type d -name 'dir_to_exclude' -prune -o -print -mtime -3 however I cannot get it... (2 Replies)
Discussion started by: horhif
2 Replies

4. Shell Programming and Scripting

Help to move folders, subfolders and files from unix to windows

Hi Unix Gurus, I am able to copy only files that exist in the parent folder. My parent folder has sub folders and within sub folders there are lots files. I need to copy folder, sub folders and files from Unix to the remote windows SFTP location. The directory structure is something like... (1 Reply)
Discussion started by: shankar1dada
1 Replies

5. UNIX for Advanced & Expert Users

Copy Structure excluding some folders

Hi I want to copy the structure from one place to another. -> cd /hol/; -> find . -type d | cpio -pvdm /abc/cat; while copying the structure I want to exclude some directories like test1 and Test. I have read somewhere that this can be done with -prune option. Could anyone... (2 Replies)
Discussion started by: soumodeep123
2 Replies

6. UNIX for Dummies Questions & Answers

Delete folders and files in it - UNIX

I need to delete a folder and files in it of yesterdays and simply put this in cron. Folder name - "2010-03-2010" File name - "eprod_06_23.dmp" and "eprod_06_23.exp" Actually this folder and file is been created by a script which takes a backup of DB everyday.Thats why it creates folder and file... (3 Replies)
Discussion started by: j_panky
3 Replies

7. Linux

Finding folders/files in an RPM file

Is there a way to find a specifc folder or filename in an RPM archive? I have dozens to go through and the hunt-and-peck method is too slow. (3 Replies)
Discussion started by: ricksj
3 Replies

8. HP-UX

to get the timestamp of files from the files and folders in Unix

Hi, I had a directory and many subdirectories and files with in it. Now i want to get the timestamp of files from the files and folders recursively. :( Please help me to generate a script fort he above mentioned requirement! Appreciate for ur qick response Thanks in advance! ... (2 Replies)
Discussion started by: kishan
2 Replies

9. Filesystems, Disks and Memory

Sun UNIX Files & Folders listing

Hi guys, i'm new to UNIX and only know a small amout about it, but have just had some changes at work which now require me to interact with and work on SUN Unix systems often. I have reasonable knowledge of PC's but hope that you will be able to help me with these questions. Part1. I would like... (3 Replies)
Discussion started by: Scrat
3 Replies

10. UNIX Desktop Questions & Answers

tar backup with excluding some folders

Hi , I want to backup the root file system but the size of / is very huge so I want to exclude some file systems.Man page of tar says X option excludes files but I could not do that.I use this command $ tar -cvf deneme.tar -X exc . $ cat exc sql kkm I think there... (2 Replies)
Discussion started by: kudret_gulcan
2 Replies
Login or Register to Ask a Question