加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – “ls *”的输出不一致

发布时间:2020-12-14 01:38:17 所属栏目:Linux 来源:网络整理
导读:只是混淆了命令“ls *”的输出.我在Ubuntu 11.10和Redhat Enterprise 6.3中测试了下面的场景,得到了相同的结果. 壳牌日志 $uname -a Linux 2.6.32-279.19.1.el6.x86_64 #1 SMP Sat Nov 24 14:35:28 EST 2012 x86_64 x86_64 x86_64 GNU/Linux$echo $0 -bash$c
只是混淆了命令“ls *”的输出.我在Ubuntu 11.10和Redhat Enterprise 6.3中测试了下面的场景,得到了相同的结果.

壳牌日志

$uname -a
   Linux 2.6.32-279.19.1.el6.x86_64 #1 SMP Sat Nov 24 14:35:28 EST 2012 x86_64 x86_64 x86_64 GNU/Linux
$echo $0
   -bash
$cd test
$ls
$ls *             *<== at first,no file/directory under current work directory*
ls: cannot access *: No such file or directory
$mkdir abc        *<== create a new directory "abc"*
$ls *             *<== output of "ls *" is empty but directory "abc" has been created.*
$mkdir abcd       *<== create the second directory "abcd"*
$ls *             *<== at this point,all the directories("abc" and "abcd") are displayed.*
abc:

abcd:

任何人都可以解释为什么在创建目录“abc”后输出“ls *”为空?谢谢.

解决方法

这主要是因为glob模式是由shell扩展的,而不是ls本身.

因此,在创建一个空的abc目录后,发出:

$ls *

调用ls的结果就像输入一样:

$ls abc

其中列出了abc的内容.由于abc为空,因此不打印任何内容.

以同样的方式,在创建abcd之后,发出:

$ls *

调用ls的结果就像输入一样:

$ls abc abcd

并且由于传递了两个目录,因此ls会在列出其(空)内容之前将每个目录打印为标题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读