我正在尝试将ls的结果提供给Perl脚本。 ls的手册页指示使用-x开关,ls应该每行输出一个条目。但是,似乎ls和ls -x产生完全相同的输出。现在,如果我做ls -1,我得到所需的输出。那么,-x开关实际上做了什么?
答案 0 :(得分:2)
我不知道你在哪里读到-x
每行列出一个文件,但这是错误的。 man page表示-x
按行而不是按列列出文件(即两个连续的文件将显示在两个连续的行而不是两个连续的列中。)
您正在寻找的选项是-1
。
答案 1 :(得分:2)
它显示在行中而不是每行一个条目
ls display
aaaaaaaaa ccccccccc eeeeeeeeee ggggggggg
bbbbbbbbb ddddddddd ffffffffff hhhhhhhhh
ls - x display
aaaaaaaaa bbbbbbbbbb ccccccccc ddddddddd
eeeeeeeee ffffffffff ggggggggg hhhhhhhhh
答案 2 :(得分:1)
根据:man ls
* List entries in multiple columns by specifying either the -C or -x flag. The -C flag is the default format when output is to a tty. The ls command displays single
column output if file or directory names are too long.
事实上,-x是另一种说法-C的方式,它告诉ls每列输出几个文件。
你可能想要:
ls -1
但是如果您尝试将文件列表提供给另一个命令,请不要使用ls。
看看:http://mywiki.wooledge.org/BashPitfalls(第1项,但也读了整篇文章,信息非常丰富)