Register
It is currently Tue Jul 29, 2014 2:53 pm

Script Help, again...


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Mon Jul 04, 2011 9:34 pm   

Joined: Mon Jul 04, 2011 9:29 pm
Posts: 3
Location: Richmond, Canada
Hi, all:

My folder structure is like

Quote:
A
-----a
-----b
B
-----a
-----b
C
-----a
-----b
....
Z
-----a
-----b


In each subfolder a or b, there are a lot of files, but no subsubfolders.
I'd love to remove all subfolders named "a" and the files under them, but leave "b" as intact. How to do that?

Thank you ...

Best Regards
Pei


Top
 Profile WWW  
 PostPosted: Mon Jul 04, 2011 10:56 pm   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
Code:
rm -Rf ./[A-Z]/a

You can replace [A-Z] with a(nother) wildcard as well.


Top
 Profile  
 PostPosted: Tue Jul 05, 2011 12:19 pm   
User avatar

Joined: Wed Jun 08, 2011 8:27 am
Posts: 189
Location: outer Shpongolia
I don't think he means A to Z literally, but multiple directories... so I would use an array or a brace expansion (depending on how many directories there are).

Code:
dirs=(dir1 dir2 dir3 dir4 ... dirN)

for d in "${dirs[@]}"; do
    rm -rf "$d/a"
done


Code:
rm -rf {dir1,dir2,dir3,dir4,...,dirN}/a


Or if your question is « How would I remove only one subdir from every directory? » and that the directory is not always called « a », then it's another issue.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP