Need script to remove millions of tmp files in /html/cache/ directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need script to remove millions of tmp files in /html/cache/ directory
# 1  
Old 05-03-2011
Lightbulb Need script to remove millions of tmp files in /html/cache/ directory

Hello,

I just saw that on my vps (centOS) my oscommerce with a seo script
has created millions of tmp files inside the /html/cache/ directory.

I would need to remove all those files (millions), I tried via shell but the vps
loads goes to very high and it hangs, is there some way to do a bash script to:

delete the files little by little by checking the load of the VPS and balance this operation

Thanks Smilie
# 2  
Old 05-04-2011
Code:
cd /html/cache
pwd

# You must confirm you are under the right folder, because below command will clean all files from the current folder.
Code:
find . -type f -exec rm -f {} \;

# 3  
Old 05-04-2011
Basically that command will overload the vps and hang it. Smilie

What I was looking for was something that could balance the server load and remove those files.

Thanks Smilie
# 4  
Old 05-04-2011
You could sleep after deleting some files.
Code:
#!/bin/bash
let I=1
find /html/cache -type f -print |while read FILE_NAME
do
 rm $FILE_NAME
 let I++
 if [ $I -ge 1000 ]; then
  sleep 1
  let I=1
 fi
done

# 5  
Old 05-04-2011
The "hang" you're describing: is it just that the console doesn't produce any output for quite some time, or does it really stop? If it stops, how did you check this?

If it's really, really stopping you could try reducing the I/O load by using ionice, eg. ionice -c 3 find . -type f

Also, if you use \+ instead of \; to terminate the -exec command to pass multiple filenames at once, instead of invoking the command for each file.
# 6  
Old 05-04-2011
Can we get a more exact sizing of the problem:

How big is the directory file itself?
Code:
ls -lad /html/cache

How long does it take to traverse the tree? And how many files in the tree?
Code:
date ; find /html/cache/ -type f -print | wc -l  ; date


Can you expand a bit about your CentOS VPS?
Are you renting a virtual computer from somewhere on the internet, or is this something you manage yourself?

If this is long-distance, the volume of output from commands must be important, but I can't see how running file deletes can hang the VPS. This is assuming that there is no rollback facility or something which would be crippled by high volumes of file deletes. I must assume that it did not collapse when the files were created - which is surely a similar load.

Assuming /html/cache is a simple directory structure and can be quiesced with no files open I'd be tempted to rename the directory, create a new replacement with identical permissions, and then delete the original at my leisure.

Last edited by methyl; 05-09-2011 at 09:18 AM..
# 7  
Old 05-04-2011
I think it hangs because first it try to find/list all files within folder and then operate... if you are fine to delete that folder itself and create a new one that would speed up...

---------- Post updated at 07:22 PM ---------- Previous update was at 07:18 PM ----------

#!/bin/bash
cd /html/
mv cache cache.bak
mkdir cache
rm -rf cache.bak
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to find the GB files in /tmp directory in remote server

Hi, i need help on shell scripting. Main intention of the script is step 1: ssh to remote server Step 2: cd /tmp in remote server Step 3: in tmp i want to grep only files and directories which are in GB sizes All the servers list file is - tmpsrv.txt vi tmpsrv.txt ... (17 Replies)
Discussion started by: kumar85shiv
17 Replies

2. Shell Programming and Scripting

Parse multiple html files in directory

I have downloaded source code for 97 files using: wget -x -i link.txt then run a rename loop: for file in * do mv $file $file.txt done to keep the html tags but make the file a text that can be parsed. In each of the 97 txt files the gene # is variable, but the gene is associated... (15 Replies)
Discussion started by: cmccabe
15 Replies

3. UNIX for Dummies Questions & Answers

Script to remove zip files from a directory

Hi Folks, There is a job which generates a .zip files every day at /usr/app/generated directory , now please advise for the script that will delete this zip files permanently.but while deleting it should make sure that it will not delete the last two days recently generated zip files and this... (1 Reply)
Discussion started by: punpun66
1 Replies

4. UNIX for Dummies Questions & Answers

Redirecting tmp files of SORT into different directory

Hey Guys, I am facing an annoying scenario, fewer times when I execute the sort command, it throws out on error saying that "No Space on available on /var/tmp/<temp file name>. May be it is set to /var/tmp directory. I was wondering, if I cant redirect the temporary file creation to any other... (3 Replies)
Discussion started by: abhisheksunkari
3 Replies

5. Shell Programming and Scripting

Script to search for a character in files in a Directory & remove it

Hi All, Am new to both Unix & this Forum - Need some help on a script that I am trying to write: In a Directory i have few text files which might or might not contain some text that I am trying to find. Once that text is found in any of the files, it needs to be removed from the file ... (6 Replies)
Discussion started by: rituparna_gupta
6 Replies

6. Shell Programming and Scripting

How to remove urls from html files

Does anybody know how to remove all urls from html files? all urls are links with anchor texts in the form of <a href="http://www.anydomain.com">ANCHOR</a> they may start with www or not. Goal is to delete all urls and keep the ANCHOR text and if possible to change tags around anchor to... (2 Replies)
Discussion started by: georgi58
2 Replies

7. Shell Programming and Scripting

Script That Can navigate to 3 differents directory & remove files under them

Hi I am Trying to Write a script that can goto 4 different directorys on the server & remove the Files older then 30 days ?? /logs logs1 logs2 logs3 Now I need to remove files under logs1 logs2 logs3 which are older then 30 days whose name stat 'sit' , 'mig','bld' . in... (3 Replies)
Discussion started by: Beginner123
3 Replies

8. Web Development

html link to images in /tmp directory

Because of permission issues, I need to link to images in my web page which are stored in /tmp which of course is located in the root directory but my actual html page is much further down in another directory. I thought the the following code should work, but the image comes up as a broken link:... (2 Replies)
Discussion started by: Solerous
2 Replies

9. Shell Programming and Scripting

perl script related /tmp directory

hi friends. i have to make a perl script to generate all users and space(how much they are using) and files(how much files they have) and time(how much time that accessed /tmp buffer) from /tmp directory. please provide me guidance. regards pranesh b. mishra (2 Replies)
Discussion started by: praneshmishra08
2 Replies

10. Shell Programming and Scripting

Script to remove all empty files within the directory structure?

Hi I need to write a shell script which basically searches for all the empty files within the directory structure, lists them before asking the user to confirm if they would like to delete them. If the user deletes the file then a notice would appear confirming the file is deleted. I've be... (5 Replies)
Discussion started by: cat123
5 Replies
Login or Register to Ask a Question