我正在尝试将ls的结果提供给Perl脚本。 ls的手册页指出使用-x开关,ls应该每行输出一个条目。 但是,ls和ls -x似乎产生完全相同的输出。 现在,如果我做ls -1,我得到所需的输出。 那么,-x开关实际上做了什么?
我不知道你在哪里读到, -x
列出每行一个文件,但这是错误的。 手册页说-x
按行而不是按列来列出文件(即两个连续的文件将显示在两个连续的行而不是两个连续的列中)。
你正在寻找的选项是-1
。
它在行中显示,而不是每行一个条目
ls display aaaaaaaaa ccccccccc eeeeeeeeee ggggggggg bbbbbbbbb ddddddddd ffffffffff hhhhhhhhh ls - x display aaaaaaaaa bbbbbbbbbb ccccccccc ddddddddd eeeeeeeee ffffffffff ggggggggg hhhhhhhhh
根据: 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,但也读取整个事情,非常翔实)