During deleting just miss some folders


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting During deleting just miss some folders
# 1  
Old 08-17-2006
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.
# 2  
Old 08-17-2006
MySQL test directory query ans

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 Smilie
# 3  
Old 08-17-2006
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.
# 4  
Old 08-17-2006
cd to the directory and run
$ find -maxdepth 1 \! -name "test2" -exec rm -rf {} \;

Look at https://www.unix.com/showpost.php?p=3...32&postcount=3 if your version of find hasn't maxdepth option
# 5  
Old 08-17-2006
Try...
Code:
cd test
rm !(test2)

# 6  
Old 08-17-2006
Hitori thanks,
works fine.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Windows batch command for deleting particular pattern named folders in temp

Hi All,' I need to write a windows bat program to delete particular folders with naming pattern scoped_dir45666 (for example)(including contents) with batch program. For that I am using below code: @echo off cd /D %temp% for /d %%D in (*) do rd /s /q "%%D" del /f /q * i got above... (0 Replies)
Discussion started by: onenessboy
0 Replies

2. UNIX for Dummies Questions & Answers

Rsync not deleting destination files/folders

Hi All, I want delete all files from destination folder. I am trying below commands rsync -avFF --delete-after /home/vizion/source/ /home/vizion/destination/ I need to be delete all file/fodders from destination Any body have idea ? Please correct me. (3 Replies)
Discussion started by: Chenchireddy
3 Replies

3. Shell Programming and Scripting

Do i miss counter or what

hello this script should show all users and space they used without problem : ls /home >> /root/users.txt cat /root/users.txt | while read line; do space=`du -s /home/$line` echo "$line space is $space" shift done but when i remove pipe ,script run without any output: ls /home... (4 Replies)
Discussion started by: nimafire
4 Replies

4. Shell Programming and Scripting

Help with Deleting Folders Script

Hi all new to the forums. Very beginner at shell scripting. What I'm trying to do is this: Is the directory empty prior to removal of it? If not, inform the user that the directory is not empty and if the user wants to remove it remove or move the files in it first. But I'm stuck.. It checks... (3 Replies)
Discussion started by: rduckett1456
3 Replies

5. Shell Programming and Scripting

Deleting empty folders

Hey, I need help with writing a shell script that deletes empty folders..anyone? :) Thank you! (5 Replies)
Discussion started by: putukas
5 Replies

6. Shell Programming and Scripting

Deleting files without folders.

How can I delete all the files in subfolders without folders (preserving directory scructure). P.S. I have a huge variety of computer books organized in subfolders (admin web hardw programming_langs) .. but I don't need them - the only way to know something now is GOOGLE (I've realized now)...... (1 Reply)
Discussion started by: Xcislav
1 Replies

7. AIX

Miss filesets

Hello everyone I updated a partition from TL06 to TL09, everything looks ok. I check the errpt comand, lppchk -v and both are fine. But when I type this command I got this $ instfix -i |grep ML All filesets for 5300-02_AIX_ML were found. All filesets for 5.3.0.0_AIX_ML were... (3 Replies)
Discussion started by: lo-lp-kl
3 Replies

8. UNIX for Dummies Questions & Answers

Use pipes but miss a action

please delete and see other post. Hi, Im using awk to go through every line, but i have to use it twice as the first awk finds all the lines with a number in one field and the pipes it to wc, and the second does the same as the first but it has a extra pipe into sort and uniq that finds all... (2 Replies)
Discussion started by: fredted40x
2 Replies

9. Shell Programming and Scripting

Finding duplicate lines and deleting folders based on them

Hi, I have research data, which is organized to 100 folders numbered 00-99. I have many sets of 100 folders, for different values of initial parameters. For some reason, the computer that ran the program to gather the data, didn't always create a unique seed for each folder. I anticipated that... (1 Reply)
Discussion started by: Jopi
1 Replies

10. Shell Programming and Scripting

deleting files and folders matching criteria

Hello, I'm spendind hours trying to figure out how a script could remove files and folders older than 30days in a given volume (/dataVolumes/Booba.1.0). Within this volume, all users have their personal folder that starts with "RC-..", so the script should skip them for deletion. I will... (4 Replies)
Discussion started by: H3001
4 Replies
Login or Register to Ask a Question