使用选项时显示完整路径
我经常在 Unix (AIX / KSH) 中使用这个列表命令:
ls -Artl
它显示的文件如下:
-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
,这不起作用选项。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我使用这个命令:
I use this command:
从 spacedrop 答案优化...
并且您可以使用 ls 选项
optimized from spacedrop answer ...
and you can use ls options
只需使用查找工具即可。
findabsolute_path
在我的 Linux 机器上显示完整路径,而
findrelative_path
则不会。
simply use find tool.
find absolute_path
displays full paths on my Linux machine, while
find relative_path
will not.
我编写了一个名为 fullpath 的 shell 脚本,其中包含此代码,每天使用它:
将其放在 PATH 中的某个位置,并使其可执行(chmod 755 fullpath),然后只需使用
完整路径 文件或目录
I wrote a shell script called fullpath that contains this code, use it everyday:
Put it somewhere in your PATH, and make it executable(chmod 755 fullpath) then just use
fullpath file_or_directory
您可以结合使用 find 命令和 ls 命令。使用路径 (.) 和选择器 (*) 来缩小您要查找的文件的范围。将 find 命令放在反引号中。 -name 的参数是双引号星号双引号,以防您无法阅读它。
You can combine the find command and the ls command. Use the path (.) and selector (*) to narrow down the files you're after. Surround the find command in back quotes. The argument to -name is doublequote star doublequote in case you can't read it.
这个技巧怎么样......
我认为这对空目录有问题,但如果另一张海报有调整,我会更新我的答案。另外,您可能已经知道这一点,但考虑到它的长度,这可能是一个很好的别名候选者。
[更新]根据评论添加了一些调整,谢谢大家。
[更新]正如评论所指出的,您可能需要根据 shell(bash 与 zsh)调整匹配器表达式。我重新添加了旧命令以供参考。
What about this trick...
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.
试试这个,对我有用:
ls -d /a/b/c/*
Try this, works for me:
ls -d /a/b/c/*
使用此命令:
而不是:
来获取列表中的完整路径。
Use this command:
instead of:
to get the full path in the listing.