LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-25-2013, 10:54 PM   #1
nicksu
Member
 
Registered: Dec 2012
Posts: 35

Rep: Reputation: Disabled
problem when rmdir find


Hi,I have come accross the erros as below:

[ssh@Nick aa]$ mkdir a
[ssh@Nick aa]$ find -name 'a' -ls
272665 4 drwxr-xr-x 2 ssh nick 4096 Mar 26 10:50 ./a
[ssh@Nick aa]$ find -name 'a' -exec rmdir {} \;
find: `./a': No such file or directory
[ssh@Nick aa]$ ls
list md md1 test

I have create a folder and when I find and rmdir it,it turns out as No such file or directory but it exactly remove the empty directory.
Can anybody tell me why ?
 
Old 03-25-2013, 11:18 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 2,962

Rep: Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268
The find command has no notion of what the program invoked by "-exec" is going to do, and the normal behavior of find is to recurse into any directories it encounters. So, find evaluates the expression "-name 'a' -exec rmdir {} \;" and then attempts to recurse into the directory "./a" it just found.

When you are going to have find removing things, it's usually advisable to use the "-depth" option to cause find to recurse into a directory before preforming any action on the directory itself. In fact, that is essential if you want find to remove a directory that needs to have its contents deleted before the directory itself can be removed. That would have happened automatically if you had used the "-delete" action instead of "-exec rmdir ...", since "-depth" is implied by "-delete".
 
Old 03-26-2013, 12:00 AM   #3
nicksu
Member
 
Registered: Dec 2012
Posts: 35

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rknichols View Post
The find command has no notion of what the program invoked by "-exec" is going to do, and the normal behavior of find is to recurse into any directories it encounters. So, find evaluates the expression "-name 'a' -exec rmdir {} \;" and then attempts to recurse into the directory "./a" it just found.

When you are going to have find removing things, it's usually advisable to use the "-depth" option to cause find to recurse into a directory before preforming any action on the directory itself. In fact, that is essential if you want find to remove a directory that needs to have its contents deleted before the directory itself can be removed. That would have happened automatically if you had used the "-delete" action instead of "-exec rmdir ...", since "-depth" is implied by "-delete".
Noted,thank you
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
rmdir not rm'ing lumix Linux - General 4 03-29-2007 10:24 PM
i deleted rmdir jzocco Linux - Newbie 13 04-12-2006 01:19 PM
Why a directory can not be able rmdir? backpacker Linux - Software 3 11-21-2005 07:07 AM
rmdir namit Linux - Software 2 10-23-2005 03:26 PM
rmdir Fatal_3rr0r Linux - General 3 06-23-2003 05:25 PM


All times are GMT -5. The time now is 02:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration