how can I seriously MASS delete .cnf files from a server....
Moderator: General Moderators
how can I seriously MASS delete .cnf files from a server....
A friend's system uses flat file caching and the extention type is .txt.cnf , and we are trying to figure out how to set a php script to the
/home/
directory and just blast / delete all those .txt.cnf files' away. ( there are ten-hundreds of thousands of small files of them, not a very good system he had but I'm trying to clean up his mess ).
ty
/home/
directory and just blast / delete all those .txt.cnf files' away. ( there are ten-hundreds of thousands of small files of them, not a very good system he had but I'm trying to clean up his mess ).
ty
- tasteslikepurple
- Forum Commoner
- Posts: 46
- Joined: Thu Jan 26, 2006 3:38 am
- Location: Bath, UK
this bit of code should do it
(note: I haven't tested it, if it doesn't work come back and shout at me and either me or another nice person will fix it)
Code: Select all
function customDelete ($dir, $pattern)
{
if(is_dir($dir))
{
if ($handle=opendir($dir))
{
while($file=readdir($handle))
{
if($file!="." && $file!=".." && strpos ($file, $pattern) !== false)
{
if(!is_dir($dir."/".$file))
{
unlink ($dir."/".$file);
}
}
}
}
else
{
trigger_error ( $dir . " isn't a directory", E_USER_ERROR);
}
closedir($handle);
return true;
}
// now call the function
customDelete ("/home", ".txt.cnf");Weirdan | Please use
The main problem is the purely enourmous NUMBER of .txt.cnf files on the server, we are talking tens or hundreds of thosuands and I think that is where my old recursive delete function would fail ...
Weirdan | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Parse error: syntax error, unexpected $end in
I am getting that error message it says on the last line of the code....
Also, I edited a second copy of this to delete only if the file is in a folder called "/static/" to delete just .txt files from the cache dir...Code: Select all
<?
function customDelete ($dir, $pattern)
{
if(is_dir($dir))
{
if ($handle=opendir($dir))
{
while($file=readdir($handle))
{
if($file!="." && $file!=".." && strpos ($file, $pattern) !== false && preg_match("/\/static\/.*?\.txt/is",$file) )
{
if(!is_dir($dir."/".$file))
{
//unlink ($dir."/".$file);
echo $dir."/".$file."<br>\n";
}
}
}
}
else
{
// trigger_error ( $dir . " isn't a directory", E_USER_ERROR);
}
closedir($handle);
return true;
}
// now call the function
customDelete("/home/info0001/public_html/~subdomains/", ".txt");
?>Weirdan | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
- tasteslikepurple
- Forum Commoner
- Posts: 46
- Joined: Thu Jan 26, 2006 3:38 am
- Location: Bath, UK
add another closing curly bracket before the else and it will fix the problem. your function won't fail based on the number of files, php should be able to handle it fine, it's only dealing with them one at a timeDeseree wrote:Parse error: syntax error, unexpected $end in
I am getting that error message it says on the last line of the code....
Also, I edited a second copy of this to delete only if the file is in a folder called "/static/" to delete just .txt files from the cache dir...
The main problem is the purely enourmous NUMBER of .txt.cnf files on the server, we are talking tens or hundreds of thosuands and I think that is where my old recursive delete function would fail ...
<?
function customDelete ($dir, $pattern)
{
if(is_dir($dir))
{
if ($handle=opendir($dir))
{
while($file=readdir($handle))
{
if($file!="." && $file!=".." && strpos ($file, $pattern) !== false && preg_match("/\/static\/.*?\.txt/is",$file) )
{
if(!is_dir($dir."/".$file))
{
//unlink ($dir."/".$file);
echo $dir."/".$file."<br>\n";
}
}
}
}
else
{
// trigger_error ( $dir . " isn't a directory", E_USER_ERROR);
}
closedir($handle);
return true;
}
// now call the function
customDelete("/home/info0001/public_html/~subdomains/", ".txt");
?>
your preg_match won't work because the file will just be the file name, not the full path with directory name.
why not call the function a few times with different arguments to delete whatever you need. i.e.
Code: Select all
customDelete ('/static', '.txt');
customDelete ('/home', '.cnf.txt');
// etc etcCode: Select all
function customDelete ($dir, $pattern)
{
if(is_dir($dir))
{
if ($handle=opendir($dir))
{
while($file=readdir($handle))
{
if($file!="." && $file!=".." && strpos ($file, $pattern) !== false)
{
if(!is_dir($dir."/".$file))
{
unlink ($dir."/".$file);
}
}
}
}
}
else
{
trigger_error ( $dir . " isn't a directory", E_USER_ERROR);
}
closedir($handle);
return true;
}Re: how can I seriously MASS delete .cnf files from a server
With the basic shell toolsDeseree wrote:delete all those .txt.cnf files' away
Code: Select all
find /home -name '*txt.cnf' -exec echo rm {} \;ok i deleted .txt.cnf files ok it seems... thanks....
now my problem is deleting .txt ONLY in /home/user/public_html/subdomain/static/ folders and lower....
I tried...
rm -fr /home/user/public_html/*/static/*.txt
but it came back " Argument list is too big"
so how would you advise this....
also i need to delete
rm -fr /home/user/public_html/*/*.html
files for another friend ( well this friend's friend's site(s) ).
Thanks again!!! This will be big help if I can do this
now my problem is deleting .txt ONLY in /home/user/public_html/subdomain/static/ folders and lower....
I tried...
rm -fr /home/user/public_html/*/static/*.txt
but it came back " Argument list is too big"
so how would you advise this....
also i need to delete
rm -fr /home/user/public_html/*/*.html
files for another friend ( well this friend's friend's site(s) ).
Thanks again!!! This will be big help if I can do this
anyone can help me test and find a working solution.... I'm needing to delete thousands and thousands of files across a very large hard drive all hundreds in diffrent folders but all named static/
so i need to delete...
/home/userXXXX/public_html/*/static/*.txt
and any folders within. or else just DELETE every single folder named static/ on the server and recreate it immediately after deleting it, but with same ch permissions and chowned 0777.
Anyone can please help, outta disk space here...
so i need to delete...
/home/userXXXX/public_html/*/static/*.txt
and any folders within. or else just DELETE every single folder named static/ on the server and recreate it immediately after deleting it, but with same ch permissions and chowned 0777.
Anyone can please help, outta disk space here...
thanks for your function, but it does not recurse sub directories, it only does for the folder you give ..... I just ran it and it did one level deep but didn't do any of the files in a folder in that directory.tasteslikepurple wrote:add another closing curly bracket before the else and it will fix the problem. your function won't fail based on the number of files, php should be able to handle it fine, it's only dealing with them one at a timeDeseree wrote:Parse error: syntax error, unexpected $end in
I am getting that error message it says on the last line of the code....
Also, I edited a second copy of this to delete only if the file is in a folder called "/static/" to delete just .txt files from the cache dir...
The main problem is the purely enourmous NUMBER of .txt.cnf files on the server, we are talking tens or hundreds of thosuands and I think that is where my old recursive delete function would fail ...
<?
function customDelete ($dir, $pattern)
{
if(is_dir($dir))
{
if ($handle=opendir($dir))
{
while($file=readdir($handle))
{
if($file!="." && $file!=".." && strpos ($file, $pattern) !== false && preg_match("/\/static\/.*?\.txt/is",$file) )
{
if(!is_dir($dir."/".$file))
{
//unlink ($dir."/".$file);
echo $dir."/".$file."<br>\n";
}
}
}
}
else
{
// trigger_error ( $dir . " isn't a directory", E_USER_ERROR);
}
closedir($handle);
return true;
}
// now call the function
customDelete("/home/info0001/public_html/~subdomains/", ".txt");
?>
your preg_match won't work because the file will just be the file name, not the full path with directory name.
why not call the function a few times with different arguments to delete whatever you need. i.e.
p.s. this version should work (got the extra bracket in it)Code: Select all
customDelete ('/static', '.txt'); customDelete ('/home', '.cnf.txt'); // etc etc
Code: Select all
function customDelete ($dir, $pattern) { if(is_dir($dir)) { if ($handle=opendir($dir)) { while($file=readdir($handle)) { if($file!="." && $file!=".." && strpos ($file, $pattern) !== false) { if(!is_dir($dir."/".$file)) { unlink ($dir."/".$file); } } } } } else { trigger_error ( $dir . " isn't a directory", E_USER_ERROR); } closedir($handle); return true; }
How can a folder have the same permissions if it needs to be chmodded 0777?? (Assuming you meant chmod since i don't expect a user 0777 to exist that will own the files)Deseree wrote: or else just DELETE every single folder named static/ on the server and recreate it immediately after deleting it, but with same ch permissions and chowned 0777.
find /home/wherever -type f -iname 'static' -exec echo rm -f {} \;
From now ion t's up to you to read the find manpage..
thanks for your help, i HAVE been trying to use man find and find --help but I can't get it right....timvw wrote:How can a folder have the same permissions if it needs to be chmodded 0777?? (Assuming you meant chmod since i don't expect a user 0777 to exist that will own the files)Deseree wrote: or else just DELETE every single folder named static/ on the server and recreate it immediately after deleting it, but with same ch permissions and chowned 0777.
find /home/wherever -type f -iname 'static' -exec echo rm -f {} \;
From now ion t's up to you to read the find manpage..
anyways, all of your commands did absolutely nothing.
top priority for me, is to....
rm -fr /home/*/public_html/*/static*.txt
That would work BUT the arguement list is way too long because it finds thosuands of folders and tens/hundreds of thousands of .txt files...