LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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

Reply
 
Search this Thread
Old 11-22-2007, 05:20 AM   #1
googlix
LQ Newbie
 
Registered: Oct 2007
Location: São Paulo - Brazil
Distribution: Debian Etch 4.1 r1
Posts: 12

Rep: Reputation: 0
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
 
Old 11-22-2007, 05:40 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,784

Rep: Reputation: 311Reputation: 311Reputation: 311Reputation: 311
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.
 
Old 11-22-2007, 06:03 AM   #3
dmedhora
LQ Newbie
 
Registered: Nov 2007
Posts: 10

Rep: Reputation: 0
you could try to use the -ls option of the find command.
For e.g

find / -ls
 
Old 11-22-2007, 06:07 AM   #4
indeliblestamp
Member
 
Registered: Feb 2006
Distribution: Fedora
Posts: 341
Blog Entries: 3

Rep: Reputation: 38
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

Last edited by indeliblestamp; 11-22-2007 at 06:08 AM.
 
Old 11-22-2007, 06:42 AM   #5
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
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.

Last edited by jschiwal; 11-22-2007 at 06:45 AM.
 
Old 11-23-2007, 11:40 AM   #6
googlix
LQ Newbie
 
Registered: Oct 2007
Location: São Paulo - Brazil
Distribution: Debian Etch 4.1 r1
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by arungoodboy View Post
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.

Thank You very much!!
 
Old 11-23-2007, 02:05 PM   #7
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 199Reputation: 199
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
.
|-- [-rw-rw-r-- trickyki   2714403]  ./postfix-2.3.8-i486-1stb.tgz
|-- [drwxr-xr-x trickyki      4096]  ./install
|   |-- [-rw-r--r-- trickyki      2325]  ./install/doinst.sh
|   |-- [-rw-r--r-- trickyki        64]  ./install/slack-required
|   |-- [-rw-r--r-- trickyki        28]  ./install/slack-conflicts
|   `-- [-rw-r--r-- trickyki       563]  ./install/slack-desc
 
Old 11-23-2007, 02:57 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,986
Blog Entries: 11

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
Quote:
Originally Posted by googlix View Post
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.

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.




Cheers,
Tink
 
Old 11-24-2007, 05:04 AM   #9
indeliblestamp
Member
 
Registered: Feb 2006
Distribution: Fedora
Posts: 341
Blog Entries: 3

Rep: Reputation: 38
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.
 
Old 11-24-2007, 05:18 AM   #10
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can my collegues view my CLI commands (including the output) in real time ? markraem Linux - General 1 09-25-2007 08:14 AM
Including header files and source files for classes Feenix Programming 8 09-28-2005 10:53 AM
Using 'ls' to get full path listing for mp3gain sygin Linux - Software 4 09-06-2005 08:55 AM
shell scripting full directory listing sqn Programming 4 04-13-2005 04:33 PM
recursively listing directories full paths kubicon Linux - Newbie 2 02-22-2004 03:55 PM


All times are GMT -5. The time now is 04:03 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration