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
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
06-07-2010, 08:17 AM
#1
Senior Member
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442
Rep:
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.
06-07-2010, 08:22 AM
#2
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
You can get the display you want with find rather than ls:
find /media/cdrom1
1 members found this post helpful.
06-07-2010, 08:23 AM
#3
Member
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 18.04 / CentOS 7.6
Posts: 397
Rep:
...or you can do this, which does exactly what the OP wants
ls -d $PWD/*
1 members found this post helpful.
06-07-2010, 08:30 AM
#4
Senior Member
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442
Original Poster
Rep:
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 .
06-07-2010, 09:20 AM
#5
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
OP = Original Poster
06-07-2010, 09:21 AM
#6
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Quote:
Originally Posted by
arashi256
...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 .
06-07-2010, 10:03 AM
#7
Member
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 18.04 / CentOS 7.6
Posts: 397
Rep:
Jeez, everyone's a critic
06-07-2010, 10:13 AM
#8
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
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
06-07-2010, 10:14 AM
#9
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
Quote:
Originally Posted by
arashi256
Jeez, everyone's a critic
Me too?!
06-07-2010, 09:43 PM
#10
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:
-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.
06-09-2010, 11:15 AM
#11
Senior Member
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442
Original Poster
Rep:
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.
All times are GMT -5. The time now is 07:29 AM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News