LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 09: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, 10:18 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
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-25-2013, 11:00 PM   #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



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 09:24 PM
i deleted rmdir jzocco Linux - Newbie 13 04-12-2006 12:19 PM
Why a directory can not be able rmdir? backpacker Linux - Software 3 11-21-2005 06:07 AM
rmdir namit Linux - Software 2 10-23-2005 02:26 PM
rmdir Fatal_3rr0r Linux - General 3 06-23-2003 04:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:18 AM.

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
Open Source Consulting | Domain Registration