Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

On my servers, one of the scripts that I have been using keeps creating the blank files at root and I haven't been noticed for more than over 6 months and now total files are created more than 500,000 files.

I cannot access that directory through control panel because there were too many files and I can only access with ftp. Even with ftp, ftp truncated the files by 8000 each. So I have to keep deleting 8000 each.

I tried to ask my host to delete it for me but they says they can't since it's the liability issues.

So what I want to know is how can i delete all of those 500,000 files through ftp? Since it's shared hosting, I don't have SSH access either. Hosting provider says I can request the SSH access but need to verify it and their office closed until next week. So I am stuck with ftp for now.

So please kindly let me know how can i delete massive files via ftp ?

And incase, if i can get the ssh access, please kindly let me know how can i delete the files via ssh with efficient ways ?

Filename are like this

  • closecp.139619
  • closecp.139619.1
  • closecp.139620
  • closecp.139620.1
share|improve this question
1  
As a recommendation, not by hand. Your best bet is writing a simple script to list the directory incrementally and delete the files till they're all gone. If FTP is limiting you to 8k files at once, deleting them all by hand will take a long time and require interaction. –  sam Nov 24 '11 at 14:19
    
Thank you so much for your suggestion. Any sample script for me to perform the action ? I would be really appreciated. –  spotlightsnap Nov 24 '11 at 14:38
    
    
@spotlightsnap There's some good sample code on uk3.php.net/opendir and uk.php.net/unlink. Basic idea, list the directory, preg_match the file names and unlink the ones you want deleted. –  sam Nov 24 '11 at 14:56
    
@spotlightsnap That only works if you upload the file to the server first, if you want to do it remotely do the same thing but using FTP commands to your remote server (and probably in something like Python or Perl if you don't have PHP locally) –  sam Nov 24 '11 at 14:58
add comment

5 Answers

Finally, I got it with the ftp command lines. I used "cmd" from window.

First i need to turn off the prompt with

prompt

Then delete with the following command

mdelete closecp.*
share|improve this answer
add comment

Its probably going to take a good long while deleting those files, expect high I/O during the time.

Theres lots of useful advise on how to delete lots and lots of files in this article rm-on-a-directory-with-millions-of-files

Yours might not be millions but it will be significantly slow.

share|improve this answer
    
That's the question I was looking for as a close target for this - thinks. –  Iain Nov 25 '11 at 8:23
add comment

If you can ssh to the box, you can run something like:

find /path/to/files -maxdepth 1 -name "closecp.*" -delete

That will find all the files with names of the form "closecp.*" (as you noted) in the directory /path/to/file (change this to suit your situation). The "-maxdepth 1" option will keep the "find" command from looking into subdirectories, and look only in /path/to/file.

share|improve this answer
    
can you please let me know the ftp command coz can't use ssh –  spotlightsnap Nov 25 '11 at 2:06
1  
Request SSH access and don't worry about getting rid of the files until it's approved. Then you can do it properly. –  MikeyB Nov 25 '11 at 2:33
    
Not really, it will take times to get SSH access from them and my hosting is banned due to the file exceeds limit –  spotlightsnap Nov 25 '11 at 3:38
add comment

You may be in luck and the FTP server allows server-side expanding wildcards.

Ditch your FTP GUI and whip out the shell, connect & login by the command line ftp. Type "del closecp.*" and let it churn away. Oh, it might be useful to disable prompting first (depends what system you're on).

share|improve this answer
    
Hello, thanks for letting me know that i can use with command line. I tried to use ftp command like through cmd. I tried to delete with the wildcard command which is "del closecp.*" but it response as No such file or directory. But if i delete the file like del closecp.169535, it works though. So i think it's the command line issue. Any other command lines that should i try ? –  spotlightsnap Nov 25 '11 at 2:05
    
Hmm, you may try mdelete. /edit: Ah, I just saw you found it by yourself. –  Roman Nov 25 '11 at 9:53
add comment

As sam pointed out I'd put a PHP or Perl file on your webspace which deletes the files from the directory.

Be sure the script cannot be found easily by anyone else but you and ensure the values in it cannot be overwritten via POST or GET.

share|improve this answer
    
any samples code would be really appreciated. I don't have much experience in coding. Thank you. –  spotlightsnap Nov 24 '11 at 14:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.