duanqin9507 2009-10-17 10:42
浏览 214
已采纳

使用regexp从Unix“ls -la”命令获取文件名?

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.

  • 写回答

11条回答 默认 最新

  • dpo69086 2009-10-17 11:19
    关注

    Try ls -a1F instead. 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:

    ./
    ../
    .bash_history
    .bash_logout
    .bash_profile
    .bashrc
    .emacs
    .mysql_history
    .subversion/
    .viminfo
    www/
    

    The directories have a slash / at the end.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(10条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度