Listing files including full path in the output
Hello All,
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. Thank You! Rodrigo Azevedo |
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. |
you could try to use the -ls option of the find command.
For e.g find / -ls |
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 {} \; |
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 So using find isn't necessary. |
Quote:
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!! |
When I want the full path like this, I always use the program or command tree, which neatly displays it as a tree format.
It will look something like this: Code:
[trickykid@trickykid postfix]$ tree -psutf |
Quote:
Code:
find /bin -name bash -exec ls -l {} \; 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. Cheers, Tink |
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 |
All times are GMT -5. The time now is 08:05 AM. |