Deleting multiple directories inside multiple directories


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Deleting multiple directories inside multiple directories
# 1  
Old 12-20-2011
Deleting multiple directories inside multiple directories

Hi,
Very unfamiliar with unix/linux stuff. Our admin is on vacation so, need help very quickly.

I have directories (eg 40001, 40002, etc) that each have one subdirectory (01).
Each subdir 01 has multiple subdirs (001, 002, 003, etc). They are same in each dir.

I need to keep the top and second level (eg, /40001/01), but delete the 001, 003, 004, etc.

What is the quickest way to do this? I have more than a hundred. I did about 20 individually - not fun!

Thank you immensely ahead of time.
# 2  
Old 12-20-2011
Try this first (it will prompt you for confirmation before deleting each folder):

Code:
find /top_directory -type d -mindepth 3 -ok rm -rf {} \;

Then this (you won't be prompted for anything):

Code:
find /top_directory -type d -mindepth 3 -exec rm -rf {} \;

# 3  
Old 12-20-2011
Thank you for the quick response.
I tried the first one.
It seemed to do something. But did not see the results. The directories are still there.
So, here is another explanation of the request:

I cd to a directory ksk
in there, there are directories - 40001, 40005, 60012, etc (117 of them)
in each of the above there is a directory 01
in each 01 there are directories 001, 002, etc.

I need to keep the 40001/01 structure.
I need to delete all of 001's - 00x BUT I need to keep 002's.

So, that is the time consuming part.. Going in to each and deleted everything around 002, and then coming out and into the next.

Sorry to be such a novice.

Thanks,
# 4  
Old 12-20-2011
verdepollo gave you the right answer based on what you told us. Perhaps you didn't understand that it was prompting you to say "y" to delete each file? Now that you've added a wrinkle to things, with 002, there are two additions we need to make to his command.

cd into your ksk directory, then run:
Code:
find -mindepth 3 -maxdepth 3 -type d -not -name 002

This should give you a list of all the directories that will be deleted (only the x/01/xxx dirs, excluding x/01/002). Assuming that looks good to you, run it again, but tack the delete code on to the end, like so:
Code:
find -mindepth 3 -maxdepth 3 -type d -not -name 002 -exec rm -rf {} \;

# 5  
Old 12-21-2011
Thank you for the reply and sorry for the confusion - i am confused myself when it comes to unix/linux.

I entered the first command got the following response::
Code:
find: illegal option --m
find: illegal option --i
find: illegal option --n
find: illegal option --e
find: illegal option --p
find: illegal option --t
find: illegal option --h
find: 3: no such file or directory

(I wonder where the 'd' went from 'mindepth')

i have triple checked what i typed and tried it twice.

thanks!

Last edited by radoulov; 12-21-2011 at 01:41 PM.. Reason: Code tags!
# 6  
Old 12-21-2011
I suppose knowing your OS and version could help here... type:
Code:
n12:/home/vbe $ what /usr/bin/find
/usr/bin/find:
        61      1.16  src/bos/usr/ccs/lib/libc/__threads_init.c, libcthrd, bos61B, b2007_33A0 8/2/07 13:09:21
        40        1.83.2.60  src/bos/usr/bin/find/find.c, cmdscan, bos61F, 0902A_61F 12/17/08 11:36:00

# 7  
Old 12-21-2011
thank you, folks.
while waiting, in continued w/ my manual long way, and am done.
so, perhaps next time i run into this type of issue, i will just take a vacation too.. hehe..

thanks again for taking the time help.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Looping for multiple directories

Hi experts, I am totally stuck with this. I run a looping "for" command for multiple directories, manually, I have done this : vfor dir in A B; do cp -p $dir/X.txt X-${dir}.txt done where A and B is directory name. However, I need to run for many directories. So I have tried this :... (7 Replies)
Discussion started by: guns
7 Replies

2. Shell Programming and Scripting

perform 3 awk commands to multiple files in multiple directories

Hi, I have a directory /home/datasets/ which contains a bunch (720) of subdirectories called hour_1/ hour_2/ etc..etc.. in each of these there is a single text file called (hour_1.txt in hour_1/ , hour_2.txt for hour_2/ etc..etc..) and i would like to do some text processing in them. Each of... (20 Replies)
Discussion started by: amarn
20 Replies

3. Shell Programming and Scripting

searching different multiple directories

Suppose I have 5 different directories in some path .Is it possible to search 5 different directories using find command in one single command line. I mean something like this:- find path -type d -name dirname1 dirname2 .......... pls help (2 Replies)
Discussion started by: maitree
2 Replies

4. Shell Programming and Scripting

FTP multiple files from multiple directories

I have multiple files that starts as TRADE_LOG spread across multiple folders in the given structure.. ./dir1/1/TRADE_LOG*.gz ./dir2/10/TRADE_LOG*.gz ./dir11/12/TRADE_LOG*.gz ./dir12/13/TRADE_LOG*.gz when I do ftp uisng mput from the "." dir I am getting the below given error mput... (1 Reply)
Discussion started by: prasperl
1 Replies

5. Shell Programming and Scripting

Creation of multiple directories

I have a folder structure like the below /test/test1/test2/app /test/test3/app /test/test4/test5/app .. I need to create a new folder under "app" in all the above listed directory structure at one shot by the name "subapp" . How can we acheive this using a script . New to unix... (4 Replies)
Discussion started by: rajeshnatarajan
4 Replies

6. UNIX for Dummies Questions & Answers

Multiple search in multiple directories

Hi, I am facing the below problem I have a list of number to be searched(around 1000) files resideing in multiple directories as i dont know where it resides in. for example search string is like (abc)123456 please help. very urgent Thanks a lot Uma (3 Replies)
Discussion started by: umapearl
3 Replies

7. Shell Programming and Scripting

check if multiple directories exist else create missing directories

Hi , I 'm trying to check if multiple directories exist on a server, if not create the missing ones and print " creating missing directory. how to write this in a simple script, I have made my code complex if ; then taskStatus="Schema extract directory exists, checking if SQL,Count and... (7 Replies)
Discussion started by: ramky79
7 Replies

8. UNIX for Dummies Questions & Answers

Using ls on multiple directories

Hi, I am using ls command as below to get the list of *.edi files from 2 different subdirectories as1 & as2: /ntekupal/test$ ls ./as1/*.edi ./as2/*.edi It is giving me list of edi files in these folders as below : ./as1/6df667.edi ./as2/823ssd3.edi Now my requirement is to just get... (3 Replies)
Discussion started by: ntekupal
3 Replies

9. Shell Programming and Scripting

Using ls on multiple directories

Hi, I am using ls command as below to get the list of *.edi files from 2 different subdirectories as1 & as2: /ntekupal/test$ ls ./as1/*.edi ./as2/*.edi It is giving me list of edi files in these folders as below : ./as1/6df667.edi ./as2/823ssd3.edi Now my requirement is to just... (8 Replies)
Discussion started by: ntekupal
8 Replies

10. Shell Programming and Scripting

moving directories to new directories on multiple servers

Hi - I am new to unix scripts...I need to move several directories on multiple servers to new directories. (0 Replies)
Discussion started by: mackdaddy07
0 Replies
Login or Register to Ask a Question