Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
in the first rm command there is no option -r, therefore rm will report: cannot rm dir
in the second rm command you used -r which means recursive delete, so it will remove dir2del and everything inside. After that find cannot continue, because the currently processed (found) dir disappeared. find would continue to go inside that dir, but lost.
Also, you can use the -delete option instead of -exec. It can be used to delete an empty directory, not just files. Otherwise, if you are going to use -exec you need the rmdir utility.
Also, see discussion of directory options in the GNU findutils manual, particularly, the option -depth. BTW, -delete implies -depth, you don't have to specify it in that case.
Still, I do not understand the reason.
So, my next guess:
dir2del is found, then been deleted together with its content. (so far, no error)
nextObject is found ... (no error)
If find remembers der2del, and need to come back, then goto nextObject (cannot come back dir2del, which makes sense for that message. Why need to find the object which is already found?). But in this scenario, I somewhat worry whether or not some file/dir could be missed.
Yes, 'rm -rf dir2del/' works. But, reason for this thread is that "to remove __pycache__/*pyc". dir2del sample in #1 is the most simplified version. I think I need to use "rm -r {} ;"
you can safely delete the whole __pychace__ dir.
find is a process, rm is another one. When you exec any command which will alter the actual directory (remove/rename it) you definitely will confuse find (because that dir was already red and stored in the memory of find). find will not re-analyze the underlying directory structure, it just assumes the user won't put a halter round his own neck.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.