60

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.

64

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.

  • After your update the command does not work anymore for me. Message cannot access /mydir/mysubdir/{*,.*}: No such file or directory – TechnoCore Apr 7 '11 at 12:53
  • .* seems to match . and .. on bash, but not on zsh. (ls -A doesn't show them, so my previous suggestion only fully works on zsh, and maybe even then my .zshrc has something to do with it) – StackExchange saddens dancek Apr 7 '11 at 12:55
  • One more thing: ls -lrt -d -1 $PWD/{*,.[^.]*} would not show . and .. in sh, but in zsh shows dot-files twice. There $PWD/* seems to be sufficient. – bmk Apr 7 '11 at 13:07
  • Another challenge: you can't use wildcard filter, right? What if I want to see ls -Artl *.log with full path? – TechnoCore Apr 7 '11 at 14:12
  • you could wrap in a tiny shell script that changes the $PWD/* part. But that's probably for a different question. – Andrew White Apr 7 '11 at 14:15
40

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

14

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.

  • 1
    I like this solution better for its simplicity and ease of use. I suppose the other solution might be usable if you created an alias out of it, but realistically, nobody is going to bother to type all that in. – jsarma Jul 13 '13 at 18:15
  • Not display the full path, try ls -ltr . |more in any place, shows only filenames, not absolute paths. – Peter Krauss Jan 12 '18 at 11:24
6

I use this command:

ls -1 | xargs readlink -f
  • Depending on your file names might need to do ls -Q1 | xargs readlink -f But this worked great for me. – mlibby Aug 2 '14 at 15:52
  • 2
    that's a great solution, but what's the difference from a simple readlink -f? – user2141046 Sep 6 '15 at 13:19
  • 1
    you must have xargs aliased on your machine as 'xargs -L 1'. otherwise this doesn't work for more than one file. the command, in that case is \ls -1 | xargs -L 1 readlink -f – user2141046 Oct 6 '15 at 9:36
  • This is the only answer that really display the full path (absolute paths)! – Peter Krauss Jan 12 '18 at 11:25
  • 1
    on macOS, use the homebrew package coreutils (likely already installed) which will install greadlink instead. – Vivek Gani Nov 24 '18 at 21:14
4

optimized from spacedrop answer ...

ls $(pwd)/*

and you can use ls options

ls -alrt $(pwd)/*
  • 2
    backticks ```` are discourage now and new way to to command substitution is to use $() – Kiwy Jun 8 '18 at 15:02
  • @Kiwy ok ! doing this we get Andrew White 's answer (wich is very nice I agree) – jo_ Jun 11 '18 at 21:16
1

simply use find tool.

find absolute_path

displays full paths on my Linux machine, while

find relative_path

will not.

  • Thanks, this worked for me. I used find "/media/lubuntu/mount point/folder/". I used find "/media/lubuntu/mount point/folder/" | grep "pattern" to find the files I wanted. Any time I used that $PWD/* method as other user suggested it gave me errors. – Rublacava 3 mins ago
0

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

-1

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 "*" `

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.