Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making a script that can delete all the files in a dir

Status
Not open for further replies.

Larshg

Programmer
Mar 1, 2001
187
DK
Hi

I trying to delete 10000 files in a directory, for this I am using a script - but I can't get it to work.

1) I do a "ls > del" - this gives me a file contaning the file names of all the files that I want to delete.

2) This is my script that I use to run though the file and deleting all the files - CAN'T CET IT TO WORK
#!/bin/ksh
for item in 'cat del'
do
rm $item
echo $item
done


It tells me that cat is not a file - I tryede removing cat from the script - but them it just deletes the file "del"

Thanks
 
problem is that you need to type
`cat file`
not
'cat file'
for your script to work
ls -a gives you all filenames in directory
ls -A gives you names of all files & dirs except . and .. which are not the ones you want to delete
eg
>for one in `ls -A` ... etc

(what about rm -rf /tmp/* )
 
find . -exec /usr/bin/ls -l {} \;

us the ls -l command for testing,
then change it to rm -f or rm -rf
if you are satisfied that it works correctly.

Robert Robert G. Jordan
Unix Sys Admin
Sleepy Hollow, Illinois U.S.A.

FREE Unix Scripts
 
heres a couple of option (based on SCO )

## interactive file deletion, DULL ..
filelist=`ls -l|awk '{ print $9 }'`
for file in $filelist
do
rm -i $file
done

## quick file deletion (doesn't affect . and ..
cd /offending-dir
rm * ***************************************
Party on, dudes!
[cannon]
 
How about this...

if [ -d full_directory_path_name ]
then
cd full_directory_path_name
rm *
fi -Bobby s-)
bwgunn@icqmail.com
 
When you kernel is configured for small argument use

#!/bin/ksh
cat del | while read item
do
rm $item
echo $item
done
Gregor.Weertman@mailcity.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top