During deleting just miss some folders

There is directory test:
> ls -rtl
total 12
drwxr-xr-x 2 root sys 4096 Aug 17 09:57 test2
-rw-r--r-- 1 user1 group1 16 Aug 17 10:00 test
-rw-r--r-- 1 user1 group1 16 Aug 17 10:00 test1
-rw-r--r-- 1 user1 group1 16 Aug 17 10:01 test12
-rw-r--r-- 1 user1 group1 16 Aug 17 10:01 test13

subdirectory test2 belong to root and of course I can't change permissions . test2 folder has a lot of files and subfolders. I'd like to delete everything in test folder except test2. When I delete everything in test folder it take a lot of time to read test2.
How could I delete everything in test folder except test2 folder, during deleting just miss test2 folder?

Maybe create script in awk or csh, something like:

rm.csh test2

means delete all except test2 folder.

Hi junior,
Why dont u do a simple cd to test directory.And then

rm -f test test1*

If i get ur problem correctly, it should do the task.
why create a script for such a task at all :confused:

Hello,
it's not easy to delete one by one,
because in really I have a lot of files and folders in test directory.
It was just example.

cd to the directory and run
$ find -maxdepth 1 \! -name "test2" -exec rm -rf {} \;

Look at The UNIX and Linux Forums - Free Tech Support if your version of find hasn't maxdepth option

Try...

cd test
rm !(test2)

Hitori thanks,
works fine.