Tag Archive for file

Count directory entries in given directories

#!/usr/bin/perl
$ARGV[0] = '.' unless @ARGV;
for my $dir (@ARGV) {
opendir DIR, $dir or die "$dir: $!
";
$file =~ m:^.: or ++$count
while ($file = readdir DIR);
closedir DIR;
}
print "$count
";
exit 0;

source

Append Line to a File

echo "<string to append>" >> <file>

#Example:

echo "My string" >> /home/user/myfile.txt

source

postcript R

postscript(file = "permittivities.eps",
width = 14, height=12,onefile = TRUE, family = "Helvetica",
title = "R Graphics Output", fonts = NULL,    paper = "special", bg="white", pointsize=16, pagecentre=TRUE)

source

Simple Logfile

$handle = fopen('./mylog.log', 'a');
fwrite($handle, "test");
fclose($handle);

source

How to remove files that are over 1 day old

find /tmp/ -type f -mtime +1 -exec rm {} ;

source

PHP File Editor

<?php
$loadcontent = "test-edit.php";

if($_POST['save_file']) {
$savecontent = stripslashes($_POST['savecontent']);
$fp = @fopen($loadcontent, "w");
if ($fp) {
fwrite($fp, $savecontent);
fclose($fp);
print "<html><head><META http-equiv="refresh" content="0;URL=$_SERVER[PHP_SELF]"></head><body>";

}
}
$fp = @fopen($loadcontent, "r");
$loadcontent = fread($fp, filesize($loadcontent));
$lines = explode("
", $loadcontent);
$count = count($lines);
$loadcontent = htmlspecialchars($loadcontent);
fclose($fp);
for ($a = 1; $a < $count+1; $a++) {
$line .= "$a
";
}
?>

<p><font face="tahoma">Simply edit the page and hit save!</font></p>

<form method=post action="<?=$_SERVER[PHP_SELF]?>">
<input type="submit" name="save_file" value="Save"><br /><br />
<table width="100%" valign="top" border="0" cellspacing="1" cellpadding="1">
<tr>
<td width="3%" align="right" valign="top"><pre style="text-align: right; padding: 4px; overflow: auto; border: 0px groove; font-size: 12px; font-face:verdana;" name="lines" cols="4" rows="<?=$count+3;?>"><?=$line;?></pre></td>
<td width="97%" align="left" valign="top"><textarea style="text-align: left; padding: 0px; overflow: auto; border: 3px groove; font-size: 12px; font-face:verdana;" name="savecontent" cols="150" rows="<?=$count;?>" wrap="OFF"><?=$loadcontent?>

source

create new files

# whatever arguments are given at the command line are
# taken to be the names for new text files,
# which are then created:

open OUT, ">$ARGV[0]" or die $!;
seek OUT,0,0 and print OUT " ";
close OUT;

source