Unix ls command: show full path when using options

2019-01-16 05:26发布

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.

6条回答
萌系小妹纸
2楼-- · 2019-01-16 05:51

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.

查看更多
Root(大扎)
3楼-- · 2019-01-16 05:52

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 "*" `
查看更多
beautiful°
4楼-- · 2019-01-16 05:56

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.

查看更多
劳资没心,怎么记你
5楼-- · 2019-01-16 05:59

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

查看更多
你好瞎i
6楼-- · 2019-01-16 06:00

I use this command:

ls -1 | xargs readlink -f
查看更多
贼婆χ
7楼-- · 2019-01-16 06:05

optimized from spacedrop answer ...

ls $(pwd)/*

and you can use ls options

ls -alrt $(pwd)/*
查看更多
登录 后发表回答