How can I produce a regular expressions pattern that returns the filename from any one of these lines? (I will search one line at a time).
drwxrwxrwx 4 apache apache 4096 Oct 14 09:40 .
drwxrwxrwx 11 apache apache 4096 Oct 13 11:33 ..
-rwxrwxrwx 1 apache apache 16507 Oct 17 10:16 .bash_history
-rwxrwxrwx 1 apache apache 33 Sep 1 09:36 .bash_logout
-rwxrwxrwx 1 apache apache 176 Sep 1 09:36 .bash_profile
-rwxrwxrwx 1 apache apache 124 Sep 1 09:36 .bashrc
-rwxrwxrwx 1 apache apache 515 Sep 1 09:36 .emacs
-rw------- 1 christoffer christoffer 11993 Sep 18 10:00 .mysql_history
drwxrwxrwx 3 apache apache 4096 Sep 1 09:48 .subversion
-rwxrwxrwx 1 christoffer christoffer 9204 Oct 14 09:40 .viminfo
drwxrwxrwx 14 apache apache 4096 Oct 12 07:39 www
The search is done using PHP, but I guess that doesn’t really make a difference. 🙂
EDIT: The file listing is retrieved by a SSH connection and that is why I don’t use a built in PHP-function. I need this full listing to see whether or not a file is actually a directory.
Try
ls -a1Finstead. That will list you all entries (-a), one per line (-1), with additional information about the file type appended to the name (-F).You will then probably get something like this for your directory:
The directories have a slash
/at the end.