在目录名称前面删除斜线
我正在尝试重新夺回C壳和TCSH的一些简单性。我有一个简单的别名,让我列出目录(别名lsdd'ls | grep /'< /code>)。我找到了一个带有几种解决方案的帖子,没有一个特别令人满意。例如,
ls -d */
除非没有子目录,否则效果很好,在这种情况下,您会收到错误消息 - 不是完全优雅。
echo */
没有给出该错误,但列表不像单列那样容易读取。
因此,我一直在/etc
中进行路由,以查找bash定义其ls
命令的位置,以便它使用颜色,以便它剥离/遵循目录名称。这似乎是做一些芽的好地方。
ls
命令中的目录名称中的bash strashs在哪个启动文件中?
I'm trying to recapture some of the simplicity of the c-shell and tcsh. I had a simple alias that allowed me to list directories (alias lsdd 'ls | grep /'
). I found a post with several solutions, none of which were particularly satisfying. For instance,
ls -d */
works well unless there are no sub-directories, in which case you get an error message--not exactly elegant.
echo */
doesn't give that error, but the list is not as easily readable as a single column.
So, I have been routing around in /etc
to find where bash defines its ls
command so that it uses color, and so that it strips the /
following the directory name. That seems to be a great place to do some bud nipping. In what startup file does bash strip slashes from directory names in an ls
command?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只想列出而没有落后斜线的目录,并且在单列中
ls
不一定是最佳实用程序。别名在某种程度上过时了。如今建议使用功能。如果默认情况下没有子目录,则打印单个
*
。为了摆脱它,我们可以暂时设置nullglob
选项。在下文中,我们记录该选项的初始状态,然后将其恢复:If you want to list only directories without the trailing slash and in a single column
ls
is not necessarily the best utility. And aliases are somehow obsolete; functions are recommended nowadays.If there are no sub-directories by default a single
*
is printed. To get rid of it we can temporarily set thenullglob
option. In the following we record the option's initial state and restore it afterwards: