免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4978 | 回复: 8
打印 上一主题 下一主题

如何查看当前目录下,第一个文件??? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-06-27 15:20 |只看该作者 |倒序浏览
ls 会查看当前目录下的所有文件,而且有序,我现在只想查看第一个文件,并将它删除,如何实现啊???

论坛徽章:
2
射手座
日期:2014-10-10 15:59:4715-16赛季CBA联赛之上海
日期:2016-03-03 10:27:14
2 [报告]
发表于 2011-06-27 15:23 |只看该作者
回复 1# 〓BigBigWolf〓


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

论坛徽章:
0
3 [报告]
发表于 2011-06-27 15:26 |只看该作者
回复 2# yinyuemi


    谢谢,大虾。

论坛徽章:
0
4 [报告]
发表于 2011-06-27 15:29 |只看该作者
回复 2# yinyuemi


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

论坛徽章:
2
射手座
日期:2014-10-10 15:59:4715-16赛季CBA联赛之上海
日期:2016-03-03 10:27:14
5 [报告]
发表于 2011-06-27 15:38 |只看该作者
回复 4# 〓BigBigWolf〓


   
-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

论坛徽章:
23
15-16赛季CBA联赛之吉林
日期:2017-12-21 16:39:27白羊座
日期:2014-10-27 11:14:37申猴
日期:2014-10-23 08:36:23金牛座
日期:2014-09-30 08:26:49午马
日期:2014-09-29 09:40:16射手座
日期:2014-11-25 08:56:112015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:49:0315-16赛季CBA联赛之山东
日期:2017-12-21 16:39:1915-16赛季CBA联赛之广东
日期:2016-01-19 13:33:372015亚冠之山东鲁能
日期:2015-10-13 09:39:062015亚冠之西悉尼流浪者
日期:2015-09-21 08:27:57
6 [报告]
发表于 2011-06-27 15:56 |只看该作者
ls | head -1 就可以了

论坛徽章:
0
7 [报告]
发表于 2011-06-27 15:58 |只看该作者
ls|head -1|xargs /bin/rm -f

论坛徽章:
0
8 [报告]
发表于 2011-06-29 09:52 |只看该作者
本帖最后由 〓BigBigWolf〓 于 2011-06-29 09:53 编辑

回复 7# jieao111


    也行,谢谢了。xargs /bin/rm看不懂

论坛徽章:
0
9 [报告]
发表于 2011-06-30 16:29 |只看该作者
你们都没判断文件是目录还是文件啊?
如果第一个是一个目录怎么办?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP