怎么理解ls `ls`这个命令?
-
- 帖子: 104
- 注册时间: 2008-09-10 21:06
怎么理解ls `ls`这个命令?
在终端下执行 ls `ls`(那个 ` 是键盘上方的数字鍵 1 左边那个按键,而不是单引号!)
输出结果第一行报错,但从第二行开始显示了当前目录下的所有文件(子文件夹中的文件也被递归的显示出来了)
不明白为什么会产生这个结果?
输出结果第一行报错,但从第二行开始显示了当前目录下的所有文件(子文件夹中的文件也被递归的显示出来了)
不明白为什么会产生这个结果?
- kofshower
- 帖子: 1343
- 注册时间: 2007-03-13 11:23
- 联系:
Re: 怎么理解ls `ls`这个命令?
理解上存在讹误,没有递归,才两层。ls -R 才是递归.此外,你的ls是哪个ls,定义alias了把:
"We are all in the mud, but some of us are looking at the stars." (Oscar Wilde)
We are not born for ourselves.
人生天地间,并非为自己
Homepage:http://sites.google.com/site/polarisnotme/
We are not born for ourselves.
人生天地间,并非为自己
Homepage:http://sites.google.com/site/polarisnotme/
-
- 帖子: 104
- 注册时间: 2008-09-10 21:06
Re: 怎么理解ls `ls`这个命令?
第一行报的错是: ls: 无法访问主题: 没有该文件或目录
但在我的当前目录下有这个名为“主题"的文件夹,用ls -l命令 能查询出来,它的权限为rwxr-xr-x,但用命令ls 主题 却报错,错误信息也是 ls: 无法访问主题: 没有该文件或目录
但在我的当前目录下有这个名为“主题"的文件夹,用ls -l命令 能查询出来,它的权限为rwxr-xr-x,但用命令ls 主题 却报错,错误信息也是 ls: 无法访问主题: 没有该文件或目录
-
- 帖子: 104
- 注册时间: 2008-09-10 21:06
Re: 怎么理解ls `ls`这个命令?
ls,没有定义alias,就是系统的 内建的命令。
- kofshower
- 帖子: 1343
- 注册时间: 2007-03-13 11:23
- 联系:
Re: 怎么理解ls `ls`这个命令?
看看自己的env
"We are all in the mud, but some of us are looking at the stars." (Oscar Wilde)
We are not born for ourselves.
人生天地间,并非为自己
Homepage:http://sites.google.com/site/polarisnotme/
We are not born for ourselves.
人生天地间,并非为自己
Homepage:http://sites.google.com/site/polarisnotme/
- xhy
- 帖子: 3916
- 注册时间: 2005-12-28 1:16
- 系统: Ubuntu 12.10 X64
- 来自: 火星
-
- 帖子: 104
- 注册时间: 2008-09-10 21:06
Re: 怎么理解ls `ls`这个命令?
恩,谢谢了,文件命后面跟了个空格,所以报了错。文件名不能有空格吗?xhy 写了:有文件名中间带IFS了 通常是个空格
能否再帮我解释下以下两个命令为什么会显示不同的结果:
ls|ls
ls `ls`
管道与引用有点混淆不清了:它们都是把一个命令的输出作为另一个命令的输入吗?
- kofshower
- 帖子: 1343
- 注册时间: 2007-03-13 11:23
- 联系:
Re: 怎么理解ls `ls`这个命令?
\来转义
"We are all in the mud, but some of us are looking at the stars." (Oscar Wilde)
We are not born for ourselves.
人生天地间,并非为自己
Homepage:http://sites.google.com/site/polarisnotme/
We are not born for ourselves.
人生天地间,并非为自己
Homepage:http://sites.google.com/site/polarisnotme/
- xhy
- 帖子: 3916
- 注册时间: 2005-12-28 1:16
- 系统: Ubuntu 12.10 X64
- 来自: 火星
Re: 怎么理解ls `ls`这个命令?
a | b a命令的结果通过管道传递给b,并不是作为参数,效果相当于b运行后从终端取得输入
b `a` a命令的结果直接作为调用b命令的参数
一个命令不一定同时支持管道和参数,或者对于两个地方的输入行为定义不一样
b `a` a命令的结果直接作为调用b命令的参数
一个命令不一定同时支持管道和参数,或者对于两个地方的输入行为定义不一样
目前负债150多万
-
- 帖子: 104
- 注册时间: 2008-09-10 21:06
Re: 怎么理解ls `ls`这个命令?
太感谢你了:
刚才测试发现如果从终端取得的输入对于a命令毫无意义的话,整个命令a | b还是可以运行成功,不过效果就相当于只执行b命令了。如exit | lsxhy 写了:a | b a命令的结果通过管道传递给b,并不是作为参数,效果相当于b运行后从终端取得输入
-
- 帖子: 1
- 注册时间: 2007-03-14 21:41
Re: 怎么理解ls `ls`这个命令?
想将ls的返回结果给ls做参数的话,可以这样做
代码: 全选
ls | xargs ls $*
-
- 帖子: 104
- 注册时间: 2008-09-10 21:06
Re: 怎么理解ls `ls`这个命令?
请问这个$*怎么解释?goomoott2 写了:想将ls的返回结果给ls做参数的话,可以这样做
代码: 全选
ls | xargs ls $*
- xhy
- 帖子: 3916
- 注册时间: 2005-12-28 1:16
- 系统: Ubuntu 12.10 X64
- 来自: 火星
Re: 怎么理解ls `ls`这个命令?
Dic4000 写了:请问这个$*怎么解释?goomoott2 写了:想将ls的返回结果给ls做参数的话,可以这样做
代码: 全选
ls | xargs ls $*
代码: 全选
Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, it
expands to a single word with the value of each parameter separated by the first character of the IFS special
variable. That is, "$*" is equivalent to "$1c$2c...", where c is the first character of the value of the IFS
variable. If IFS is unset, the parameters are separated by spaces. If IFS is null, the parameters are joined
without intervening separators.
代码: 全选
ls | xargs ls
目前负债150多万