Unix ls命令:使用选项时显示完整路径 [英] Unix ls command: show full path when using options

查看:2257
本文介绍了Unix ls命令:使用选项时显示完整路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常在Unix(AIX / KSH)中使用此列表命令:



ls -Artl p>

它显示的文件如下:



-rw-r - r-- 1 myuser mygroup 0 Apr 2 11:59 test1.txt

-rw-r - r-- 1 myuser mygroup 0 Apr 2 11:59 test2.txt



我想修改命令以显示文件的完整路径。例如:



-rw-r - r-- 1 myuser mygroup 0 Apr 2 11:59 /usr/test1.txt

-rw-r - r-- 1 myuser mygroup 0 Apr 2 11:59 /usr/test2.txt



任何想法?



我发现了几个使用 pwd find 但是 - 就我所知 - 如果我想保留 ls

解决方案

这个技巧怎么样...

  ls -lrt -d -1 $ PWD /{*,.*} 

OR

ls -lrt -d -1 $ PWD / *

我认为这有空目录的问题,但如果另一个海报有一个调整,我会更新我的答案。此外,你可能已经知道这个,但这可能是一个好的候选人的别名,因为它的冗长。



[更新]根据评论添加了一些调整。 [update]如你根据shell(bash vs zsh)调用匹配器表达式的注释所指出的。我已重新添加了旧的命令以供参考。


I often use this list command in Unix (AIX / KSH):

ls -Artl

It displays the files as this:

-rw-r--r-- 1 myuser mygroup 0 Apr 2 11:59 test1.txt
-rw-r--r-- 1 myuser mygroup 0 Apr 2 11:59 test2.txt

I would like to modify the command such a way that the full path of the file is displayed. For example:

-rw-r--r-- 1 myuser mygroup 0 Apr 2 11:59 /usr/test1.txt
-rw-r--r-- 1 myuser mygroup 0 Apr 2 11:59 /usr/test2.txt

Any ideas?

I found several resolution methods using pwd or find but - as far as I see - this does not work work if I want to keep the ls options.

解决方案

What about this trick...

ls -lrt -d -1 $PWD/{*,.*}

OR

ls -lrt -d -1 $PWD/*

I think this has problems with empty directories but if another poster has a tweak I'll update my answer. Also, you may already know this but this is probably be a good candidate for an alias given it's lengthiness.

[update] added some tweaks based on comments, thanks guys.

[update] as pointed out by the comments you may need to tweek the matcher expressions depending on the shell (bash vs zsh). I've re-added my older command for reference.

这篇关于Unix ls命令:使用选项时显示完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆