![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| find command with prune help | venu_nbk | UNIX for Dummies Questions & Answers | 2 | 05-28-2007 03:25 AM |
| Find command with prune and exec options | Sebarry | UNIX for Dummies Questions & Answers | 2 | 06-19-2006 01:07 AM |
| Find command with prune and exec | Sebarry | UNIX for Advanced & Expert Users | 1 | 06-18-2006 10:43 AM |
| Use -prune with find command on AIX | FuzzySlippers | UNIX for Dummies Questions & Answers | 5 | 11-08-2002 06:24 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Find command uisng -prune or -only
I've run into a brick wall using the -prune command to avoid walking sub-directories. Does any one have any suggestions on how I avoid walking the sub-directories when finding files in the following example?
I want to find all files older than 30 days in the dir1 directory and only the dir1 directory. Directory structure looks something like this, for example : /dir1/dir2/dir3..... Here's the find command that I'm using right now: find /dir1 -prune -o -name '*' -mtime +30 -print > filelist.lst However, I keep getting output for files located in the dir2 and dir3 directories as well. Any thoughts on how to keep this find command from walking the sub-directories? |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
#3
|
|||
|
|||
|
Tried that already
i did see that solution but it does not work in my case. Here's what I had using that solution :
find /dir1 \( ! -name /dir1 -prune \) -name '*' -mtime +30 -print > filelist.lst However, when I check the filelist.lst file it is empty and shouldn't be because there are files in /dir1 that are older than 30 days. |
|
#4
|
|||
|
|||
|
It seems to work for me on Solaris.
Code:
bash-3.00# pwd /dir1 bash-3.00# ls -l total 4 drwxr-xr-x 2 root root 512 Feb 22 13:08 dir2/ -rw-r--r-- 1 root root 6 Jan 1 00:00 file1 bash-3.00# ls -l dir2/ total 0 -rw-r--r-- 1 root root 0 Jan 1 00:00 file2 bash-3.00# find . \( ! -name . -prune \) -mtime +30 ./file1 |
|
#5
|
|||
|
|||
|
Try adding the -name '*' after the -prune portion of the command and see if you get any different results.
|
|
#6
|
|||
|
|||
|
It's still working. But why are you passing that name parameter if your looking for a wildcard anyway? find will do that by default.
Code:
bash-3.00# find . \( ! -name . -prune \) -name '*' -mtime +30 ./file1 |
|
#7
|
|||
|
|||
|
That's wierd because it won't work on HP-UX 11i. The -name '*' would be a passin value from user input. It could be '*' or '*TEST' or any other wildcarded search parameter. They can also input whether or not they want to search sub-directories for the input filename(s). I'm setting a flag for the sub-directory search to determine the appropriate find command structure to use based on their inputs. So, if they want to search sub-directories of the initial search path there is no issue because I don't need to use the -prune. However, if they don't want to search sub-directories underneath the initial search path AND they enter an '*" for the filename(s) to search for I run into this issue.
Based on your results this may well be a HP-UX issue. Although I'm not positive of that at this point. |
|||
| Google The UNIX and Linux Forums |