免费注册 查看新帖 |

Chinaunix

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

ls命令的疑惑 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-04-19 12:29 |只看该作者 |倒序浏览
如果在/下面有多个文件,如file1 file2 file3 file4 file5 file6 file7 file8 file9
ls命令的结果在终端显示为:

file1       file4      file7
file2       file5      file8
file3       file6      file9

ls | head -1 结果为什么是file1,而不是file1       file4      file7

???

赐教了

论坛徽章:
0
2 [报告]
发表于 2006-04-19 12:47 |只看该作者
ls -w 80

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
3 [报告]
发表于 2006-04-19 12:55 |只看该作者
ls会自动区分输出设备

论坛徽章:
84
每日论坛发贴之星
日期:2015-12-29 06:20:00每日论坛发贴之星
日期:2016-01-16 06:20:00每周论坛发贴之星
日期:2016-01-17 22:22:00程序设计版块每日发帖之星
日期:2016-01-20 06:20:00每日论坛发贴之星
日期:2016-01-20 06:20:00程序设计版块每日发帖之星
日期:2016-01-21 06:20:00每日论坛发贴之星
日期:2016-01-21 06:20:00程序设计版块每日发帖之星
日期:2016-01-23 06:20:00程序设计版块每日发帖之星
日期:2016-01-31 06:20:00数据库技术版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-14 06:20:00
4 [报告]
发表于 2006-04-19 12:58 |只看该作者
猜的:
ls结果的排版可能是用 ANSI escape codes 作的。
而实际的文本是每行放一个文件名。

_________________________________________
把 Escape codes 和 Collating Sequences 搞混了,
不过他们都属于ANSI Escape Sequence
http://bbs.chinaunix.net/viewthr ... &extra=page%3D1
#include <stdio.h>
#include <time.h>
#include <unistd.h>
int main ()
{
        while (1)
                {
                        time_t sec=time(NULL);
                        struct tm t=*localtime(&sec);
                        printf("\x1b[2J");
                        printf("\x1b[31;40m");
                        printf("\x1b[11;36H");
                        printf("+-----^--^-----+\n");
                        printf("\x1b[12;36H");
                        printf("|\t%02d:%02d:%02d: |\n",t.tm_hour,t.tm_min,t.tm_sec);
                        printf("\x1b[13;36H");
                        printf("+-------V------+\n");
                        sleep(1);       
                }
        return 0;
}

[ 本帖最后由 yjh777 于 2006-4-21 12:22 编辑 ]

论坛徽章:
84
每日论坛发贴之星
日期:2015-12-29 06:20:00每日论坛发贴之星
日期:2016-01-16 06:20:00每周论坛发贴之星
日期:2016-01-17 22:22:00程序设计版块每日发帖之星
日期:2016-01-20 06:20:00每日论坛发贴之星
日期:2016-01-20 06:20:00程序设计版块每日发帖之星
日期:2016-01-21 06:20:00每日论坛发贴之星
日期:2016-01-21 06:20:00程序设计版块每日发帖之星
日期:2016-01-23 06:20:00程序设计版块每日发帖之星
日期:2016-01-31 06:20:00数据库技术版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-14 06:20:00
5 [报告]
发表于 2006-04-19 12:59 |只看该作者
原帖由 waker 于 2006-4-19 12:55 发表
ls会自动区分输出设备


这个听起来更有道理
_________________________________________________
发现这个也不对,见八、九楼。

[ 本帖最后由 yjh777 于 2006-4-21 10:58 编辑 ]

论坛徽章:
0
6 [报告]
发表于 2006-04-19 13:59 |只看该作者
原帖由 waker 于 2006-4-19 12:55 发表
ls会自动区分输出设备

原来如此,怪不得

论坛徽章:
0
7 [报告]
发表于 2006-04-19 14:31 |只看该作者
原帖由 waker 于 2006-4-19 12:55 发表
ls会自动区分输出设备

呵呵!一针见血

论坛徽章:
84
每日论坛发贴之星
日期:2015-12-29 06:20:00每日论坛发贴之星
日期:2016-01-16 06:20:00每周论坛发贴之星
日期:2016-01-17 22:22:00程序设计版块每日发帖之星
日期:2016-01-20 06:20:00每日论坛发贴之星
日期:2016-01-20 06:20:00程序设计版块每日发帖之星
日期:2016-01-21 06:20:00每日论坛发贴之星
日期:2016-01-21 06:20:00程序设计版块每日发帖之星
日期:2016-01-23 06:20:00程序设计版块每日发帖之星
日期:2016-01-31 06:20:00数据库技术版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-14 06:20:00
8 [报告]
发表于 2006-04-21 10:47 |只看该作者
原帖由 xxjoyjn 于 2006-4-19 12:29 发表
如果在/下面有多个文件,如file1 file2 file3 file4 file5 file6 file7 file8 file9
ls命令的结果在终端显示为:

file1       file4      file7
file2       file5      file8
file3       file6      fil ...


用 -C 选项:
[root@142 work]# ls -C | head -n1
build_env.sh  draw.sh  function2.sh  kkk         pwd2full.sh  test.sh
       The  output is to stdout, one entry per line, unless multicolumn output is
       requested by the -C option. However, for output to a terminal, it is unde-
       fined  whether  the  output  will  be  single-column  or multi-column. The
       options -1 and -C can be used to force single-column and multi-column out-
       put, respectively.

POSIX OPTIONS
       -C     List files in columns, sorted vertically.

论坛徽章:
84
每日论坛发贴之星
日期:2015-12-29 06:20:00每日论坛发贴之星
日期:2016-01-16 06:20:00每周论坛发贴之星
日期:2016-01-17 22:22:00程序设计版块每日发帖之星
日期:2016-01-20 06:20:00每日论坛发贴之星
日期:2016-01-20 06:20:00程序设计版块每日发帖之星
日期:2016-01-21 06:20:00每日论坛发贴之星
日期:2016-01-21 06:20:00程序设计版块每日发帖之星
日期:2016-01-23 06:20:00程序设计版块每日发帖之星
日期:2016-01-31 06:20:00数据库技术版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-14 06:20:00
9 [报告]
发表于 2006-04-21 10:55 |只看该作者

Collating Sequences

原帖由 waker 于 2006-4-19 12:55 发表
ls会自动区分输出设备

这个猜测也不对,是:Collating Sequences
man ls
...
       Each  of  the  lists  of  files (that of non-directory files, and for each
       directory the list of files inside) is sorted separately according to  the
       collating  sequence  in  the current locale.  When the -l option is given,
       each list is preceded by a summary line giving the total size of all files
       in the list, measured in 512-byte or 1024-byte blocks.
...


http://docs.hp.com/en/32650-90883/ch02s03.html

论坛徽章:
7
荣誉版主
日期:2011-11-23 16:44:17子鼠
日期:2014-07-24 15:38:07狮子座
日期:2014-07-24 11:00:54巨蟹座
日期:2014-07-21 19:03:10双子座
日期:2014-05-22 12:00:09卯兔
日期:2014-05-08 19:43:17卯兔
日期:2014-08-22 13:39:09
10 [报告]
发表于 2006-04-21 11:53 |只看该作者

回复 9楼 yjh777 的帖子

感觉你没有理解瓦克尔的意思,ls对不同的输出设备是有区别的,我以前做过测试。至于-C则是强制性的,和这个讨论无关。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP