<code>ls -al | awk '{print $8,$5,$6}'</code>
This will take a standard long linux file listing, and re-order it so you get the file name, number of bytes and date of creation:
<code>
test 4096 2006-11-20
test1.php 0 2007-08-05
test.txt.gz 480 2006-04-09
tomcat 4096 2007-02-27
ukcode.php?number=07971899759 455 2006-12-04
unser.php 205 2007-01-14
</code>
<code>dir | gawk "{print $4,$3,$1}"</code>
<code>
netset.txt 1,037 29/11/2007
ntent_a.xml 6,440 16/09/2008
ntent_ie.xml 1,654 16/09/2008
ntent_m.xml 5,862 16/09/2008
ntent_y.xml 5,816 16/09/2008
ntuser.dat 15,728,640 29/01/2009
persistent_state 16 04/08/2008
phone 47 22/05/2008
</code>
<code>
drwx------ 2 shawty users 4096 2006-04-10 23:51 .ssh
-rw-r--r-- 1 shawty users 193 2007-10-25 10:43 staaus.cap
-rw-r--r-- 1 shawty users 11627 2007-10-27 14:05 staceymail2
-rw-r--r-- 1 shawty users 18737 2007-10-28 00:24 staceymail3
-rw-r--r-- 1 shawty users 34040 2007-10-28 16:10 staceymail4
-rw-r--r-- 1 shawty users 182891 2007-10-26 09:28 stacymail
-rw-r--r-- 1 shawty shawty 3642 2008-10-29 17:02 startup
-rw-r--r-- 1 shawty shawty 4124 2008-10-29 17:03 startup-org
-rw-r--r-- 1 shawty users 55 2006-06-03 01:51 suck.newrc
-rw-r--r-- 1 shawty users 50 2006-06-03 01:47 sucknewsrc
-rw-r--r-- 1 shawty users 0 2008-05-15 17:20 .sudo_as_admin_successful
-rw-r--r-- 1 shawty users 23067 2006-10-12 22:34 telnet.pl
-rw-r--r-- 1 shawty users 9231834 2006-04-18 14:21 termine
</code>
<code>
<?php
// Open PHP's standard input stream
$input_stream = fopen("php://stdin","r");
// Array to store the received data
$lines = array();
// Loop & process while we receive lines
while($line = fgets($input_stream,4096)) // Note 4k lines, should be ok for most purposes
{
//Store each line in the array, ensuring we chop off the line ends
$lines[] = trim($line);
}
fclose($input_stream);
print_r($lines);
?>
</code>
<code>
shawty@poweredge:~/Articles_PHP$ ls -al ../ | php -q fancydir.php
Array
(
[0] => total 54676
[1] => drwxr-xr-x 46 shawty users 4096 2009-01-29 20:01 .
[2] => drwxr-xr-x 14 root root 4096 2009-01-13 17:17 ..
[3] => -rw-r--r-- 1 shawty users 1 2006-11-15 02:24 2
[4] => drwxr-xr-x 10 shawty users 4096 2008-05-14 17:11 20gdrive
[5] => drwxr-x--- 6 shawty users 4096 2007-04-30 16:14 4grec1
[6] => drwx------ 2 shawty users 4096 2006-05-14 17:31 a.b.p.v.files
[7] => -rw-r--r-- 1 shawty users 1863991 2006-03-06 14:24 abs-guide.pdf
[8] => -rw-r--r-- 1 shawty users 0 2006-05-23 22:42 .addressbook
[9] => -rw------- 1 shawty users 2285 2006-05-23 22:42 .addressbook.lu
[10] => drwx------ 2 shawty users 4096 2008-05-15 17:42 .aptitude
[11] => drwxr-xr-x 2 shawty shawty 4096 2009-01-29 20:01 Articles_PHP
[12] => drwxr-xr-x 3 shawty users 4096 2006-06-11 01:34 baks
[13] => -rw------- 1 shawty users 15190 2009-01-29 12:56 .bash_history
[14] => -rw-r--r-- 1 shawty users 220 2008-05-15 16:41 .bash_logout
[15] => -rw-r--r-- 1 shawty users 2298 2008-05-15 16:41 .bashrc
[16] => drwxr-xr-x 2 shawty users 4096 2006-08-07 14:39 belkinbt
[17] => drwx------ 2 shawty users 4096 2006-08-22 21:16 .cedit
==SNIP==
</code>
<code>
$count = 1;
foreach($lines as $line)
{
print $count . " : " . $line . "\n";
$count++;
}
</code>
<code>
1 : drwxr-xr-x 46 shawty users 4096 2009-01-29 20:01 .
2 : drwxr-xr-x 14 root root 4096 2009-01-13 17:17 ..
3 : -rw-r--r-- 1 shawty users 1 2006-11-15 02:24 2
4 : drwxr-xr-x 10 shawty users 4096 2008-05-14 17:11 20gdrive
5 : drwxr-x--- 6 shawty users 4096 2007-04-30 16:14 4grec1
6 : drwx------ 2 shawty users 4096 2006-05-14 17:31 a.b.p.v.files
7 : -rw-r--r-- 1 shawty users 1863991 2006-03-06 14:24 abs-guide.pdf
8 : -rw-r--r-- 1 shawty users 0 2006-05-23 22:42 .addressbook
</code>
<code>
Array
(
[0] => -rwxr-xr-x
[1] => 1
[2] => shawty
[3] => users
[4] => 2804
[5] => 2006-04-01
[6] => 23:18
[7] => .xsession
)
File Name is .xsession
Size is 2804 Bytes
It belongs to 'shawty' in the 'users' Group
and was created on 2006-04-01 at 23:18
File is Readable,Writable,Executable by shawty
File is Readable,Not Writable,Executable by members of the shawty group
File is Readable,Not Writable,Executable by everyone
Array
(
[0] => -rw-r--r--
[1] => 1
[2] => shawty
[3] => users
[4] => 119
[5] => 2006-04-01
[6] => 23:18
[7] => .xtalkrc
)
File Name is .xtalkrc
Size is 119 Bytes
It belongs to 'shawty' in the 'users' Group
and was created on 2006-04-01 at 23:18
File is Readable,Writable,Not Executable by shawty
File is Readable,Not Writable,Not Executable by members of the shawty group
File is Readable,Not Writable,Not Executable by everyone
etc.....
</code>
C:\Documents and Settings\Shawty>psinfo
PsInfo v1.75 - Local and remote system information viewer
Copyright (C) 2001-2007 Mark Russinovich
Sysinternals - www.sysinternals.com
<code>
System information for \\*******:
Uptime: 0 days 10 hours 9 minutes 31 seconds
Kernel version: Microsoft Windows XP, Multiprocessor Free
Product type: Professional
Product version: 5.1
Service pack: 2
Kernel build number: 2600
Registered organization: ********************
Registered owner: **********
Install date: 29/11/2007, 16:05:53
Activation status: ********************
IE version: 7.0000
System root: C:\WINDOWS
Processors: 2
Processor speed: 2.4 GHz
Processor type: Intel(R) Core(TM)2 Duo CPU E4600 @
Physical memory: 3582 MB
Video driver: NVIDIA GeForce 8500 GT
</code>
servers.txt
<code>
server1
server2
server3
</code>
list_installs.php
<code>
<?php
$biff = array();
$serverlist = file("servers.txt");
foreach($serverlist as $server)
{
unset($output);
exec('psinfo \\\\' . trim($server),$output);
foreach($output as $line)
{
if(preg_match('/Install\sdate:\s+(.*),\s(.*)/',$line,$matches))
{
$instdate = $matches[1];
$insttime = $matches[2];
}
}
print trim($server) . "," . $instdate . "," . $insttime . "\n";
}
?>
</code>
output_xml.php
<code>
<?php
$input_stream = fopen("php://stdin","r");
$lines = array();
while($line = fgets($input_stream,4096))
{
$lines[] = trim($line);
}
fclose($input_stream);
print "<server_installs>\n";
foreach($lines as $line)
{
$temp = explode(",",$line);
print "\t<server name=\"". $temp[0] . "\">\n";
print "\t\t<installdate>" . $temp[1] . "</installdate>\n";
print "\t\t<installtime>" . $temp[2] . "</installtime>\n";
print "\t</server>\n";
}
print "</server_installs>\n";
?>
</code>
<code>
php -q list_installs.php | php -q output_xml.php
</code>
<code>
<server_installs>
<server name="server1">
<installdate>20/09/2008</installdate>
<installtime>22:12:26</installtime>
</server>
<server name="server2">
<installdate>29/11/2007</installdate>
<installtime>16:05:53</installtime>
</server>
</server_installs>
</code>