LinuxQuestions.org
Review your favorite Linux distribution.
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 05-17-2024, 01:37 AM   #1
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,732
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Lightbulb How to delete a particular directory from all subdirectories?


I want to delete 'build' directory from everywhere on my computer without going inside all directories.

What is the way?
 
Old 05-17-2024, 02:02 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,039

Rep: Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347
find <root> -name build -type d -delete
 
1 members found this post helpful.
Old 05-17-2024, 02:26 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,152

Rep: Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125
Be careful what you wish for.

Maybe issue a print first ... :shrug:
 
1 members found this post helpful.
Old 05-28-2024, 01:55 AM   #4
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,167

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
as Syg00 suggests be careful...

If it's a VM then do a snapshot or clone it.

then do what you like to do:


find <root> -name build -type d -print << check first

if angry but happy to continue:


find <root> -name build -type d -exec rm -rf {} \;
 
Old 05-28-2024, 10:44 AM   #5
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,832

Rep: Reputation: 1219Reputation: 1219Reputation: 1219Reputation: 1219Reputation: 1219Reputation: 1219Reputation: 1219Reputation: 1219Reputation: 1219
For recursive deletion run rm -r
Code:
find <root> -name build -type d -prune -exec rm -rf {} \;
The -prune does not attempt to descend a deleted directory, can avoid an error message.

Last edited by MadeInGermany; 05-28-2024 at 10:50 AM.
 
1 members found this post helpful.
Old 05-29-2024, 04:36 PM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,691
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
I also advise caution. You can use the find command to create a list of files (in a file). Then, review(!) that list. Next, you can use the xargs command to execute a command (such as "rm") for all of the entries in that list. Finally, discard the list-file. Three(!) very-careful and very-deliberate steps.
 
  


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
what if I wanted to see all files in a directory (all subdirectories) at once? newbiesforever Linux - General 9 10-01-2018 02:21 PM
Delete all files in particular directory preetham.66666 Linux - Server 5 02-27-2015 10:52 AM
Recursively tail follow all files in a directory, all subdirectories, and so on... dragonmaximadriver Linux - General 8 01-14-2015 08:43 AM
How to delete all images from a directory/subdirectories SentralOrigin Linux - General 2 04-16-2009 02:54 AM

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

All times are GMT -5. The time now is 08:35 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