使用选项时显示完整路径

发布于 2024-10-31 03:28:38 字数 535 浏览 9 评论 0原文

我经常在 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

有什么想法吗?

我发现了几种使用 pwdfind 的解析方法,但是 - 据我所知 - 如果我想保留 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

似梦非梦 2024-11-07 03:28:39

我使用这个命令:

ls -1 | xargs readlink -f

I use this command:

ls -1 | xargs readlink -f
心的位置 2024-11-07 03:28:39

从 spacedrop 答案优化...

ls $(pwd)/*

并且您可以使用 ls 选项

ls -alrt $(pwd)/*

optimized from spacedrop answer ...

ls $(pwd)/*

and you can use ls options

ls -alrt $(pwd)/*
夏末染殇 2024-11-07 03:28:39

只需使用查找工具即可。

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.

简单爱 2024-11-07 03:28:39

我编写了一个名为 fullpath 的 shell 脚本,其中包含此代码,每天使用它:

    #!/bin/sh
    for i in $* ; do
        echo $(pwd)/$i
    done

将其放在 PATH 中的某个位置,并使其可执行(chmod 755 fullpath),然后只需使用
完整路径 文件或目录

I wrote a shell script called fullpath that contains this code, use it everyday:

    #!/bin/sh
    for i in $* ; do
        echo $(pwd)/$i
    done

Put it somewhere in your PATH, and make it executable(chmod 755 fullpath) then just use
fullpath file_or_directory

醉生梦死 2024-11-07 03:28:39

您可以结合使用 find 命令和 ls 命令。使用路径 (.) 和选择器 (*) 来缩小您要查找的文件的范围。将 find 命令放在反引号中。 -name 的参数是双引号星号双引号,以防您无法阅读它。

ls -lart `find . -type f -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.

ls -lart `find . -type f -name "*" `
天生の放荡 2024-11-07 03:28:38

这个技巧怎么样......

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

OR

ls -lrt -d -1 $PWD/*

我认为这对空目录有问题,但如果另一张海报有调整,我会更新我的答案。另外,您可能已经知道这一点,但考虑到它的长度,这可能是一个很好的别名候选者。

[更新]根据评论添加了一些调整,谢谢大家。

[更新]正如评论所指出的,您可能需要根据 shell(bash 与 zsh)调整匹配器表达式。我重新添加了旧命令以供参考。

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.

怎言笑 2024-11-07 03:28:38

试试这个,对我有用:ls -d /a/b/c/*

Try this, works for me: ls -d /a/b/c/*

成熟稳重的好男人 2024-11-07 03:28:38

使用此命令:

ls -ltr /mig/mthome/09/log/*

而不是:

ls -ltr /mig/mthome/09/log

来获取列表中的完整路径。

Use this command:

ls -ltr /mig/mthome/09/log/*

instead of:

ls -ltr /mig/mthome/09/log

to get the full path in the listing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文