rm -rf ab returns find: `./ab': No such file or directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting rm -rf ab returns find: `./ab': No such file or directory
# 1  
Old 11-12-2012
rm -rf ab returns find: `./ab': No such file or directory

Hi Gurus.

This is driving me a bit batty. I now if must be a simple matter but I cant find anything that references it.

I have a housekeeping script that searches for some huge dump directories then removes them using rm -rf.

Code:
find ./ -name 'ab' -exec rm -rf {} \;

This works but always returns the following

find: `./ab': No such file or directory

This would be ok on an "on the fly" delete, but I have this as part of a larger backup script and this message returns as something for us to error check.

Is there a way for me to delete a directory without getting this message returned?

Thanks!
# 2  
Old 11-12-2012
You get the error because find cannot find the file 'ab', not from the rm command (-f removes that error).

You can add 2> /dev/null to the very end of the command to remove the error.
This User Gave Thanks to Scott For This Post:
# 3  
Old 11-12-2012
Thanks Scott - that has resolved the issue.

Could I cheekily ask one more thing?

Quote:
You get the error because find cannot find the file 'ab', not from the rm command (-f removes that error).
How do you mean that find cant find the file? Before the rm -rf it must find it in order to delete it, right? It just seems that after the rm -rf it tries to find the file again and then presents the error.

Why am I getting the error when the file is clearly there??
# 4  
Old 11-12-2012
It's hard to know exactly where "there" is because I don't know what directory your script is in as it's being run.

But using -f with rm will suppress the "no such file or directory" error.

Code:
$ ll ab
ls: ab: No such file or directory
$ rm -f ab
$ <-- command prompt, i.e. no error message

Therefore, the error must come from find, not from rm.
This User Gave Thanks to Scott For This Post:
# 5  
Old 11-12-2012
Code:
[dj@davidjlvm dj]$ pwd
/home/dj/dj
[dj@davidjlvm dj]$ ll
total 0
[dj@davidjlvm dj]$ mkdir ab
[dj@davidjlvm dj]$ ll
total 4
drwxrwxr-x. 2 dj dj 4096 Nov 12 15:26 ab
[dj@davidjlvm dj]$ find ./ -name 'ab' -exec rm -f {} \;
rm: cannot remove `./ab': Is a directory
[dj@davidjlvm dj]$ find ./ -name 'ab' -exec rm -rf {} \;
find: `./ab': No such file or directory
[dj@davidjlvm dj]$ ll
total 0
[dj@davidjlvm dj]$

# 6  
Old 11-12-2012
find doesn't seem to like the trailing / in the path name.

Try removing it.

i.e.
Code:
find . -name .......

My find at least prints something more useful:
Code:
find: .//ab: No such file or directory

This User Gave Thanks to Scott For This Post:
# 7  
Old 11-12-2012
When -depth is not used, the find command visits a directory before its contents. So, when find sees ab, it performs the -exec and afterwards tries to descend into ab to see what's there. That's where the error message comes from.

You could use -prune to prevent the descent.
Code:
find ./ -name 'ab' -exec rm -rf {} \; -prune

Regards,
Alister
These 2 Users Gave Thanks to alister For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to find and get a file in an entire directory with an excluded directory specified?

How to get a file 'zlib.h' in an entire directory with an excluded directory specified lives under that starting directory by using find command, as it failed on: $ find . -name 'zlib.h' -a -ipath 'CHROME.TMP' -prune -o -print it'll just list entirely up (2 Replies)
Discussion started by: abdulbadii
2 Replies

2. UNIX for Beginners Questions & Answers

Linux find command returns nothing

Under one of my directories on server I have more than 500 files with different type and name. When I run the find command to list the files with 'ABC_DEFGH' in the begining of its name and older than 20 days, nothing is return as result. Though I know there are more than 400 files which their name... (10 Replies)
Discussion started by: Home
10 Replies

3. Solaris

Tilde prefix returns invalid home directory.

I am trying to find the home directory of users on a UNIX (Solaris/AIX) box using echo ~usernameThis does return the home directory for all valid users. For some reason this command also outputs home directory which are non-existent for few users who seem not to have logon access to that... (31 Replies)
Discussion started by: thinkster
31 Replies

4. Shell Programming and Scripting

for $word in $line returns filenames in the current directory unexpectedly

I am writing a script below, which has 2 loops. The outer one reads file sufffixed with a number and inner inside which loop through each line of the file and display each space delimited string. However, i find that the string printed out in the inner loop includes not only the delimited string in... (2 Replies)
Discussion started by: martie
2 Replies

5. Shell Programming and Scripting

find/grep returns no matches

Hi all! I've faced with very unintelligible error using find/grep like this: root@v29221:~# find /var/www/igor/data/www/lestnitsa.ru | grep u28507I get nothing as a result, but: root@v29221:~# grep u28507 /var/www/igor/data/www/lestnitsa.ru/_var.inc $db_name = 'u28507';... (2 Replies)
Discussion started by: ulrith
2 Replies

6. UNIX for Dummies Questions & Answers

echo statement when find returns null

Hi, How do you echo something once when a find statement returns null results? This is when using mutiple locations and mutiple arguments. The below find command the inner loop of a nested for loop where the outter loop holds the $args and the inner loop holds the locations. find... (2 Replies)
Discussion started by: tchoruma
2 Replies

7. UNIX for Dummies Questions & Answers

find command returns files with spaces, mv won't work...

Hi guys. I am trying, to move files found with the find command... Script runs fine, until it reaches a file that contains spaces... Here is what i wrote up quickly. ROOTDIR=/apps/data SEARCH=$(find /data/HDTMPRestore/home/tmq/ -type f -print | grep Mods/Input/bck | cut -c19-) for i... (1 Reply)
Discussion started by: Stephan
1 Replies

8. UNIX for Dummies Questions & Answers

how to find a file named vijay in a directory using find command

I need to find whether there is a file named vijay is there or not in folder named "opt" .I tried "ls *|grep vijay" but it showed permission problem. so i need to use find command (6 Replies)
Discussion started by: amirthraj_12
6 Replies

9. Shell Programming and Scripting

FIND returns different results in script

When I execute this line at the command prompt I get a different answer than when I run it in a script? Any ideas on how to resolve? I'm trying to find all files/dir in a directory except files that start with the word file. Once I get this command to work, I will add the "delete" part to the... (6 Replies)
Discussion started by: blt123
6 Replies

10. UNIX for Dummies Questions & Answers

cant find command that returns blank line

This is my list of sed commands: can anyone tell me where im going wrong. The script works on a file called data which contains 6 student id's and there answers for 6 questions. !/bin/sh sed -e 's/*//g' \ #replace * with nothing -e s/ /X/g' \ #replacing empty space with X -e... (2 Replies)
Discussion started by: jeffersno1
2 Replies
Login or Register to Ask a Question