Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unix ls command: show full path when using options

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.

like image 982
TechnoCore Avatar asked Apr 07 '11 12:04

TechnoCore


People also ask

How do you show the full path in Unix?

The pwd command displays the full, absolute path of the current, or working, directory.

How do I list the full path in Linux?

Use the find command. By default it will recursively list every file and folder descending from your current directory, with the full (relative) path. If you want the relative path, use: find .

What is the absolute path of ls command?

An absolute path is the full path to a file or directory. It is relative to the root directory ( / ). Note that it is a best practice to use absolute paths when you use file paths inside of scripts. For example, the absolute path to the ls command is: /usr/bin/ls .


1 Answers

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.

like image 71
Andrew White Avatar answered Sep 28 '22 10:09

Andrew White