Script to find file types and info

I'm looking for a way to inventory files on a webserver into a CSV file, and am particularly interested in certain types of files, like .php, .cgi, .pl, .py, .sh, etc. but also want the ability to find all files, including those with no extension, or specified extensions, as above, including files that have spaces or unusual characters or line returns in their names.

I saw the post here:

File Inventory Scan

which had a script that mostly worked and provided good info about the files it found, but couldn't handle files with spaces in their names (last column printed "cannot open: No such file or directory").

Ideally this script would also have columns for file user/group ownership, permissions, access, create and modification times, human readable file size, etc.

I'm on a Solaris 11 machine. I may have the ability to install packages if required.

If you only need the file names, with PHP you can use scandir() to scan the entire web directory and put all the file names in array and filter the array based on the extensions. However, if you need more info than just the filename / extension, scandir() will not provide the ownership and permissions, information.

In that case, if I was doing this, I would simply exec() a variation of the ls -lR comand in a PHP script and put each entry (file information) into an array, and then filter the array as needed.

Of course, you don't need PHP to do this, but since your are using a web server which has PHP already, you might enjoy taking the output (your file inventory) and displaying your inventory results on a web page in addition to a CSV file :wink:

See also PHP: fputcsv()

fputcsv ( resource $handle , array $fields [, string $delimiter = "," [, string $enclosure = '"' [, string $escape_char = "\\" ]]] ) : int