BashScripts.org
http://bashscripts.org/forum/

Script Help, again...
http://bashscripts.org/forum/viewtopic.php?f=16&t=1426
Page 1 of 1

Author:  jiapei100 [ Mon Jul 04, 2011 9:34 pm ]
Post subject:  Script Help, again...

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

Author:  Patsie [ Mon Jul 04, 2011 10:56 pm ]
Post subject:  Re: Script Help, again...

Code:
rm -Rf ./[A-Z]/a

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

Author:  jsz [ Tue Jul 05, 2011 12:19 pm ]
Post subject:  Re: Script Help, again...

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.

Page 1 of 1 All times are UTC - 6 hours
© 2000, 2002, 2005, 2007 phpBB Group • http://www.phpbb.com