Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I would like to know whether it's possible or not to list a file including its full path, something like this:
-rw-r--r-- 1 rodrigo admin 538 Nov 22 08:52 /etc/rodrigo.txt
I couldn't find anything about this in the ls man page so I presume that this is not possible using it. So if anyone have an alternative way of doing this I would appreciate if you could post the solution here.
The nearest that I can find is 'ls -lR' to give a recursive long-list. First the directory (with full path) is listed, then the files in that directory are listed (without path).
You might be able to combine the output of 'ls -lR' with an awk script to display the output in the format you want.
Last edited by bigrigdriver; 11-22-2007 at 05:42 AM.
As long as you include the full path name of the file or directory to list, "ls -l" will show what you want.
example:
ls /etc/rc* -l
lrwxrwxrwx 1 root root 6 2007-10-08 13:38 /etc/rc.d -> init.d
-rw-r--r-- 1 root root 611 2002-05-21 10:01 /etc/rc.d.README
-rw-r--r-- 1 root root 2772 2006-08-24 07:44 /etc/rc.splash
-rw-r--r-- 1 root root 8498 2006-08-24 07:43 /etc/rc.status
If you run a find and then pass the args to ls, the full path shows up. For example:
Code:
find /bin -name bash -exec ls -l {} \;
-rwxr-xr-x 1 root root 626028 Feb 11 2003 /bin/bash
Edit: dmedhora's solution is nicer
That's solved the problem! Thank You!
Actually I have tried this but it didn't work because I was running the find command inside the directory where the files to be listed were located so the ls -l command was showing the relative path. To resolve this all I needed to do was moving up to / and then run the find command again.
Actually I have tried this but it didn't work because I was running the find command inside the directory where the files to be listed were located so the ls -l command was showing the relative path. To resolve this all I needed to do was moving up to / and then run the find command again.
Thank You very much!!
Code:
find /bin -name bash -exec ls -l {} \;
-rwxr-xr-x 1 root root 626028 Feb 11 2003 /bin/bash
One word of caution: if you're not looking for a particular
file but want a whole list of stuff w/ sub-directories, you'd
want to change the "ls -l" to an "ls -ld" or narrow the type
in find down to "-type f" if you're not interested in directory
names at all.
Actually jschiwal's answer looks incredibly elegant. If you give the full path in the ls command itself, it works exactly as required (This also seems to be why the find command works if you give it with the path, but doesn't if you run it from the same directory).
So I vote for ls -l /etc/hosts as the neatest way to solve this.
Lets say you want the full pathname of a file, or files from the current directory, but you don't know or can't assume where you are. You could use:
ls $(pwd)/filename
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.