Unix command to delete all files from a directory




















It only takes a minute to sign up. Connect and share knowledge within a single location that is structured and easy to search. If you are not having any luck with these, you should consider reinstalling rm or switching shells. Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Learn more. How do I remove a directory and all its contents? Ask Question.

Asked 9 years, 5 months ago. Active 6 years, 2 months ago. Lilian A. Moraru Lilian A. Moraru 5, 2 2 gold badges 22 22 silver badges 21 21 bronze badges. I found this to be the more comprehensive and helpful answer, over and above the answer that was marked as Accepted. Haven't tried it. Moraru, I did some testing today. Note that this is common and not specific to rm.

Show 3 more comments. Leonid V. Fedorenchik Leonid V. Fedorenchik 7 7 silver badges 10 10 bronze badges. This should be the beautiful accepted answer. Thank you! Doesn't this glob match ". This does not work on Mac console, hidden files are still there with that command line.

Thanks for your advice and I've added more explanation for the links. Richard Holloway Richard Holloway GNU find as a -delete predicate.

You really ought to add a -- after the rm. Without that if you have a file names -rf or similar will be interpreted as arguments to rm. That will cause it to split the rm commands to having a maximum number of arguments i. You can also add -maxdepth 1 to ensure that find does not return files from any subdirectories. If you don't use this command very cautiously, you risk deleting all or most of your files.

If the subdirectory mydir exists in your current directory and it is not empty, you can delete it by entering at the Unix prompt:. For more information on the rmdir and the rm -r commands, see their man pages. At the Unix prompt, enter:. This is document abet in the Knowledge Base.

Improve this question. Tak Tak 2 2 gold badges 10 10 silver badges 21 21 bronze badges. Add a comment. Active Oldest Votes. Improve this answer. I think rm -r would do.. GMaster GMaster 5, 2 2 gold badges 25 25 silver badges 28 28 bronze badges. Can't I use rm to do this? POSIXly: find! Community Bot 1. Gilles 'SO- stop being evil' Gilles 'SO- stop being evil' k gold badges silver badges bronze badges.

Sign up or log in Sign up using Google.



0コメント

  • 1000 / 1000