Problem with find command "find: cannot open"

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with find command "find: cannot open"
# 1  
Old 11-06-2013
Problem with find command "find: cannot open"

Hello Guys ,

I am trying to run below find command in one of my SH script on a HP UX machine.

find /tmp -type f -name "MGCA*.log" -prune -exec rm -f {} \; 2>&1

I want this to check my tmp directory and delete MGCA log files .But below error message is printed on Promt :-

find: cannot open /tmp/veaintf
find: cannot open /tmp/ilmt

i removed this by directing stderror to /dev/null and it works fine.

find /tmp -type f -name "MGCA*.log" -prune -exec rm -f {} \; 2>/dev/null

My question here is :- To stop my command to look into other directories in tmp folder , i have used "prune" option. But it's not working fine for me.
Is there something wrong with my query.

Looking for your help on this.

Himanshu Sood
# 2  
Old 11-06-2013
The description of the -prune primary is:
The primary shall always evaluate as true; it shall cause find not to descend the
current pathname if it is a directory. If the −depth primary is specified, the −prune
primary shall have no effect.

Since you've used -type f before you get to the -prune, you know that the current pathname cannot be a directory.

To do what you seem to be trying to do using -prune, you could try:
find /tmp ! -name /tmp -prune -type f -name "MGCA*.log" -exec rm -f {} \;

but it seems like it would be much easier just to use:
cd /tmp
rm -f MGCA*.log

unless there are so many matching files that this would exceed ARG_MAX limits on your system.
# 3  
Old 11-06-2013
Don u rocks... Grt explanation .. This really helps .
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find . -path "*_nobackup*" -prune -iname "*.PDF" \( ! -name "*_nobackup.*" \)

These three finds worked as expected: $ find . -iname "*.PDF" $ find . -iname "*.PDF" \( ! -name "*_nobackup.*" \) $ find . -path "*_nobackup*" -prune -iname "*.PDF" They all returned the match: ./folder/file.pdf :b: This find returned no matches: $ find . -path "*_nobackup*" -prune... (3 Replies)
Discussion started by: wolfv
3 Replies

2. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

3. UNIX for Dummies Questions & Answers

find/xargs/*grep: find multi-line empty "try-catch" blocks - eg, missing ; not in a commented block

How can I recursively find all files in a directory and print out the file and first line number of any text blocks that match the below cases? This would seem to involve find, xargs, *grep, regex, etc. In summary, I want to find so-called empty "try-catch blocks" that do not contain code... (0 Replies)
Discussion started by: lifechamp
0 Replies

4. Shell Programming and Scripting

Problem with "find" and "grep" command

I want to list all files/lines which except those which contain the pattern ' /proc/' OR ' /sys/' (mind the leading blank). In a first approach I coded: find / -exec ls -ld {} | grep -v ' /proc/| /sys/' \; > /tmp/list.txt But this doesn't work. I got an error (under Ubuntu): grep:... (5 Replies)
Discussion started by: pstein
5 Replies

5. OS X (Apple)

Install Problem "can't find GLX.h"

Hi. Somewhat of a newbie. Trying to install a scientific software package DReAMM/PSC The PSC component needs to be compiled. Per instruction I use this command env MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS='-O2 -fomit-frame-pointer' \ CXXFLAGS='-O2 -fomit-frame-pointer'... (2 Replies)
Discussion started by: stoucha
2 Replies

6. Solaris

Find all "regular" files open for write on solaris?

How do I find all "regular" files on solaris(8) that are open for write ( +read as well). I tried using pfiles, and lsof commands, but not sure how to get exactly what I wanted. ps -e | awk '{ print $1 }' | xargs -i pfiles {} 2>/dev/null (10 Replies)
Discussion started by: kchinnam
10 Replies

7. UNIX for Advanced & Expert Users

command for recently modified files - "find" command not working

I have three files a.txt , b.txt , c.txt in a directory called my_dir1 .These files were created before two or three months . I have a tar file called my_tar1.tar which contains three files a.txt , b.txt , d.txt . Somebody untarred the my_tar1.tar into my_dir1 directory. So existing two files were... (1 Reply)
Discussion started by: joe.mani
1 Replies

8. Shell Programming and Scripting

Find closing brace "{" of a given open brace "{"

There is a file as: ....... some text timing () { capacitance : 9.0; incap : 0.8; cell_fall () { values ("8.9","7.8"); } } ........ some more text ####### Is there a way to directly find closing brace "{" of timing () block "{" ? (2 Replies)
Discussion started by: nehashine
2 Replies

9. Shell Programming and Scripting

"find command" to find the files in the current directories but not in the "subdir"

Dear friends, please tell me how to find the files which are existing in the current directory, but it sholud not search in the sub directories.. it is like this, current directory contains file1, file2, file3, dir1, dir2 and dir1 conatins file4, file5 and dir2 contains file6,... (9 Replies)
Discussion started by: swamymns
9 Replies

10. UNIX for Dummies Questions & Answers

How to find out the exact year in "Last modified time" using ls command

Hi, I understand that the ls command with "-l" option generates the "last modified time" of specific directory. However, some generated results displayed the "last modified time" with detail about the last modified year, for example: -rwxrwxrwx+ 1 smith dev 10876 May 16 2005 part2 ... (6 Replies)
Discussion started by: Dophlinne
6 Replies
Login or Register to Ask a Question