ls 的 Bash 别名,按“类型”打印多列
我仅使用这样的 ls 命令列出文件基名,该命令是我从 此处:
ls --color -1 . | tr '\n' '\0' | xargs -0 -n 1 basename
我想在第一列中列出所有目录,在下一列中列出所有可执行文件,最后列出所有常规文件(也许每个扩展名也有一列)。
因此,第一个(也是主要的)“挑战”是打印不同长度的多列。
您对我应该使用哪些命令来编写该脚本有什么建议吗?我应该切换到查找
吗?或者我应该只用 Perl 编写脚本?
我也希望能够选择按大小对列进行排序;-) 我不一定要寻找一个脚本来执行上述操作,但也许会提供一些关于编写此类脚本的方法的建议。
I'm listing just the file basenames with an ls command like this, which I got from here:
ls --color -1 . | tr '\n' '\0' | xargs -0 -n 1 basename
I would like to list all the directories in the first column, all the executables in the next, all the regular files last (perhaps also with a column for each extension).
So the first (and main) "challenge" is to print multiple columns of different lengths.
Do you have any suggestions what commands I should be using to write that script? Should I switch to find
? Or should I just write the script all in Perl?
I want to be able to optionally sort the columns by size too ;-) I'm not necessarily looking for a script to do the above, but perhaps some advice on ways to approach writing such a script.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
示例输出此处
通过计算每列最长的条目并将其用作宽度可以进一步改进。我将把它作为练习留给读者
Sample output HERE
This can be further improved upon by calculating what the longest entry is per-column and using that as the width. I'll leave that as an exercise to the reader