LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-07-2010, 08:17 AM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Rep: Reputation: 76
ls: displaying the whole path.


GNU/linux kernel 2.6, slackware 12.0

Hi:
Can ls display the whole path of a file? Suppose I have /media/cdrom1/*. So I want the output of ls to be

/media/cdrom1/file1
/media/cdrom2/file2
..................
/media/cdrom2/fileN

Any suggestion would be greatly appreciated. Thanks for reading.
 
Old 06-07-2010, 08:22 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
You can get the display you want with find rather than ls:

find /media/cdrom1
 
1 members found this post helpful.
Old 06-07-2010, 08:23 AM   #3
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 18.04 / CentOS 7.6
Posts: 397

Rep: Reputation: 62
...or you can do this, which does exactly what the OP wants

ls -d $PWD/*
 
1 members found this post helpful.
Old 06-07-2010, 08:30 AM   #4
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
The problem with ls -d $PWD/* is that there are white spaces in the path and it stops after finding the first one. What is the OP?

Last edited by stf92; 06-07-2010 at 08:35 AM.
 
Old 06-07-2010, 09:20 AM   #5
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
OP = Original Poster
 
Old 06-07-2010, 09:21 AM   #6
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Quote:
Originally Posted by arashi256 View Post
...or you can do this, which does exactly what the OP wants

ls -d $PWD/*
Actually it isn't "exactly" because he clearly listed one file per line in his desired output. He'd have to do:
ls -1d $PWD/* to get that your way - also it assumes he's sitting in the directory when he runs the command. The find command I listed doesn't require that or the extra option.

Last edited by MensaWater; 06-07-2010 at 09:22 AM.
 
Old 06-07-2010, 10:03 AM   #7
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 18.04 / CentOS 7.6
Posts: 397

Rep: Reputation: 62
Jeez, everyone's a critic
 
Old 06-07-2010, 10:13 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Actually the find command descend recursively into the directory tree, unless the -maxdepth option is specified:
Code:
find /media/cdrom1 -maxdepth 1
but the same result, as already noticed, can be obtained by means of
Code:
ls -1d /media/cdrom1/*
in this case they are the shell globbin' capabilities that show the full path, that is the actual command executed after glob expansion is
Code:
ls -1d /media/cdrom1/file1 /media/cdrom1/file2 ... /media/cdrom1/fileN
 
Old 06-07-2010, 10:14 AM   #9
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by arashi256 View Post
Jeez, everyone's a critic
Me too?!
 
Old 06-07-2010, 09:43 PM   #10
Karl Godt
Member
 
Registered: Mar 2010
Location: Kiel , Germany
Distribution: once:SuSE6.2,Debian3.1, aurox9.2+3,Mandrake?,DSL? then:W7st,WVHB, #!8.10.02,PUPPY4.3.1 now:Macpup
Posts: 314

Rep: Reputation: 45
-a for all and wildcards

Code:
root@ubuntu:~# cd /                                            
root@ubuntu:/# ls -a                                           
.   bin   cdrom  etc   initrd.img  media  opt   rofs  sbin  sys  usr  vmlinuz
..  boot  dev    home  lib         mnt    proc  root  srv   tmp  var         
root@ubuntu:/# ls -F
bin/    dev/   initrd.img@  mnt/   rofs/  srv/  usr/
boot/   etc/   lib/         opt/   root/  sys/  var/
cdrom/  home/  media/       proc/  sbin/  tmp/  vmlinuz@
root@ubuntu:/# ls -l
insgesamt 6         
drwxr-xr-x   2 root root  1649 2008-12-04 13:33 bin
drwxr-xr-x   2 root root   209 2008-12-04 13:34 boot
dr-xr-xr-x  20 root root  6144 2009-01-14 08:30 cdrom
drwxr-xr-x  17 root root 14820 2010-06-08 00:39 dev  
drwxr-xr-x 109 root root   700 2010-06-08 00:46 etc  
drwxr-xr-x   3 root root    60 2010-06-08 00:38 home 
lrwxrwxrwx   1 root root    32 2008-12-04 13:14 initrd.img -> boot/initrd.img-2.6.27-7-generic                                                                  
drwxr-xr-x  17 root root  3097 2008-12-04 13:33 lib                             
drwxr-xr-x   2 root root    39 2008-10-29 22:09 media                           
drwxr-xr-x   2 root root     3 2008-10-20 12:27 mnt                             
drwxr-xr-x   2 root root     3 2008-10-29 21:59 opt                             
dr-xr-xr-x 148 root root     0 2010-06-08 00:38 proc                            
drwxr-xr-x  19 root root   245 2008-12-04 13:35 rofs                            
drwxr-xr-x   5 root root   100 2010-06-08 00:42 root                            
drwxr-xr-x   2 root root  2468 2008-12-04 13:33 sbin                            
drwxr-xr-x   2 root root     3 2008-10-29 21:59 srv                             
drwxr-xr-x  12 root root     0 2010-06-08 00:38 sys                             
drwxrwxrwt   9 root root   240 2010-06-08 00:46 tmp                             
drwxr-xr-x  11 root root    80 2008-10-29 22:04 usr                             
drwxr-xr-x  14 root root   149 2008-10-29 22:07 var                             
lrwxrwxrwx   1 root root    29 2008-12-04 13:15 vmlinuz -> boot/vmlinuz-2.6.27-7-generic                                                                        
root@ubuntu:/# ls -aFl                                                          
insgesamt 6                                                                     
drwxr-xr-x  23 root root   300 2010-06-08 00:38 ./                              
drwxr-xr-x  23 root root   300 2010-06-08 00:38 ../                             
drwxr-xr-x   2 root root  1649 2008-12-04 13:33 bin/                            
drwxr-xr-x   2 root root   209 2008-12-04 13:34 boot/                           
dr-xr-xr-x  20 root root  6144 2009-01-14 08:30 cdrom/                          
drwxr-xr-x  17 root root 14820 2010-06-08 00:39 dev/                            
drwxr-xr-x 109 root root   700 2010-06-08 00:46 etc/                            
drwxr-xr-x   3 root root    60 2010-06-08 00:38 home/                           
lrwxrwxrwx   1 root root    32 2008-12-04 13:14 initrd.img -> boot/initrd.img-2.6.27-7-generic                                                                  
drwxr-xr-x  17 root root  3097 2008-12-04 13:33 lib/                            
drwxr-xr-x   2 root root    39 2008-10-29 22:09 media/                          
drwxr-xr-x   2 root root     3 2008-10-20 12:27 mnt/                            
drwxr-xr-x   2 root root     3 2008-10-29 21:59 opt/                            
dr-xr-xr-x 148 root root     0 2010-06-08 00:38 proc/                           
drwxr-xr-x  19 root root   245 2008-12-04 13:35 rofs/                           
drwxr-xr-x   5 root root   100 2010-06-08 00:42 root/                           
drwxr-xr-x   2 root root  2468 2008-12-04 13:33 sbin/                           
drwxr-xr-x   2 root root     3 2008-10-29 21:59 srv/                            
drwxr-xr-x  12 root root     0 2010-06-08 00:38 sys/                            
drwxrwxrwt   9 root root   240 2010-06-08 00:46 tmp/                            
drwxr-xr-x  11 root root    80 2008-10-29 22:04 usr/                            
drwxr-xr-x  14 root root   149 2008-10-29 22:07 var/                            
lrwxrwxrwx   1 root root    29 2008-12-04 13:15 vmlinuz -> boot/vmlinuz-2.6.27-7-generic                                                                        
root@ubuntu:/# ls -aFl /var/*                                                   
/var/backups:                                                                   
insgesamt 2                                                                     
drwxr-xr-x  2 root root   28 2008-10-29 21:59 ./                                
drwxr-xr-x 14 root root  160 2008-10-29 22:07 ../                               
-rw-r--r--  1 root root 1795 2008-10-29 22:09 infodir.bak                         

/var/log:
insgesamt 2104
drwxr-xr-x 11 root   root    560 2010-06-08 00:39 ./
drwxr-xr-x 14 root   root    160 2008-10-29 22:07 ../
drwxr-xr-x  2 root   root      3 2008-10-09 00:10 apparmor/
        
-rw-rw-r--  1 root   utmp   4224 2010-06-08 00:39 wtmp                
-rw-r--r--  1 root   root    308 2008-10-29 22:09 wvdialconf.log      
-rw-r--r--  1 root   root 337860 2010-06-08 02:06 Xorg.0.log          

/var/mail:
insgesamt 0
drwxrwsr-x  2 root mail   3 2008-10-29 21:59 ./
drwxr-xr-x 14 root root 160 2008-10-29 22:07 ../

/var/opt:
insgesamt 0
drwxr-xr-x  2 root root   3 2008-10-29 21:59 ./
drwxr-xr-x 14 root root 160 2008-10-29 22:07 ../

/var/run:
insgesamt 48
drwxr-xr-x 15 root       root        620 2010-06-08 00:46 ./
drwxr-xr-x 14 root       root        160 2008-10-29 22:07 ../

drwxr-xr-x  2 root       root         60 2010-06-08 00:39 xauth/
drwxr-xr-x  4 root       root         80 2010-06-08 00:39 xdmctl/

lrwxrwxrwx  1 root root   7 2008-12-04 13:15 mail -> ../mail/
drwxr-xr-x  3 root root  29 2008-10-29 22:05 openoffice/

/var/tmp:
insgesamt 0
drwxrwxrwt  4 root   root    60 2010-06-08 00:39 ./
drwxr-xr-x 14 root   root   160 2008-10-29 22:07 ../
drwx------  3 root   root   100 2010-06-08 00:42 kdecache-root/
drwx------  8 ubuntu ubuntu 240 2010-06-07 22:47 kdecache-ubuntu/
root@ubuntu:/#
Code:
root@ubuntu:/# find /tmp/*
/tmp/adept.debconf        
/tmp/kde-root             
/tmp/kdesudo-Ti8220-xauth 


/tmp/ksocket-ubuntu/kdeinit4__0
/tmp/ssh-OZqhxL7592
/tmp/ssh-OZqhxL7592/agent.7592
root@ubuntu:/#
 
1 members found this post helpful.
Old 06-09-2010, 11:15 AM   #11
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Very useful your post, Karl Godt. By the way, I assume there's no way that ls displays only directory names. I always do this combining ls with some tool like grep, but to have it done by means of ls alone would be the ideal, I think. And if it cannot be done, then I think the Unix command ls lacks some functionality. Cheers.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
displaying path cj4331 Linux - Newbie 5 02-20-2008 06:19 PM
Need help in displaying the relative path in C zacodi Programming 4 07-06-2007 01:55 PM
Need help in displaying the relative path zacodi Linux - Newbie 2 07-05-2007 04:14 PM
Question in displaying the relative path oliviapesayco Programming 1 06-30-2007 03:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:29 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration