+ -
当前位置:首页 → 问答吧 → 如何查看当前目录下,第一个文件???

如何查看当前目录下,第一个文件???

时间:2011-06-27

来源:互联网

ls 会查看当前目录下的所有文件,而且有序,我现在只想查看第一个文件,并将它删除,如何实现啊???

作者: 〓BigBigWolf〓   发布时间: 2011-06-27

回复 〓BigBigWolf〓


  rm  $(ls |grep -m1 '.')

作者: yinyuemi   发布时间: 2011-06-27

回复 yinyuemi


    谢谢,大虾。

作者: 〓BigBigWolf〓   发布时间: 2011-06-27

回复 yinyuemi


    没看明白后面那个 -m 1 和 '.' 是什么意思。

作者: 〓BigBigWolf〓   发布时间: 2011-06-27

回复 〓BigBigWolf〓


   

QUOTE:
-m NUM, --max-count=NUM
              Stop  reading  a file after NUM matching lines.  If the input is standard input from a
              regular file, and NUM matching lines are output, grep ensures that the standard  input
              is  positioned  to just after the last matching line before exiting, regardless of the
              presence of trailing context lines.  This  enables  a  calling  process  to  resume  a
              search.   When  grep  stops  after NUM matching lines, it outputs any trailing context
              lines.  When the -c or --count option is also used,  grep  does  not  output  a  count
              greater than NUM.  When the -v or --invert-match option is also used, grep stops after
              outputting NUM non-matching lines.



'.' to match any single character

作者: yinyuemi   发布时间: 2011-06-27

ls | head -1 就可以了

作者: ly5066113   发布时间: 2011-06-27

ls|head -1|xargs /bin/rm -f

作者: jieao111   发布时间: 2011-06-27