LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 08-17-2011, 10:54 PM   #1
zeusys
Member
 
Registered: Jun 2006
Posts: 31

Rep: Reputation: 0
ls */ explanation


hi
would someone please explain these arguments.I know what these do,but I want to know the meaning of these characters.For example I know "ls /" lists files/directories under root directory.but in "ls */" what * and / refer to?

ls */

and

ls -ld */


thank you
 
Old 08-17-2011, 11:15 PM   #2
cargod_hera
LQ Newbie
 
Registered: Apr 2010
Location: Dallas, TX
Distribution: Simply MEPIS, OpenArtist, Ubuntu 10.04, Mint, Elive, Epidemic, Kongoni, Anibus, BackTrack4
Posts: 29

Rep: Reputation: 2
Just as "ls" lists the contents of the directory that you are in, "ls -l" gives you a list of the sub-directories and gives you information about those sub-directories (i.e. permissions, owner, size, etc.).
The command "ls */" shows not only the contents of the directory that you are in but also the contents of the sub-directories. Likewise, using "ls -ld */" will show the directory contents and information about the sub-directories.

There are some additional "ls" arguments that you might find helpful as well. Using "ls ~" will show the contents of your home directory. Using "ls ../" shows the contents of the parent directory (the parent of the directory you are in) and "ls /" lists the contents of the root directory.
 
Old 08-18-2011, 12:07 AM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 2,968

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
It's your shell, not ls, that expands the "*", and ls simply acts on the argument list that the shell supplies. A simple "*" expands to a list of all non-dot files in the current directory, where the term "files" includes not only ordinary files but also directory files, device files, named pipes, ... -- all the things that can appear in a Unix file system. When you append a trailing slash, "*/", the list is restricted to just directory files. So,
Code:
ls */
would invoke ls with a list of all of the non-dot directory files in the current directory, and ls would dutifully list the names and contents of each of those directories. If you include the "-ld" flags:
Code:
ls -ld */
then ls gets the same list as before, but the "-l" flag instructs it to produce a long-format listing, and the "-d" flag tells it to list only the names of directories, not their contents.

Last edited by rknichols; 08-18-2011 at 12:09 AM.
 
Old 08-18-2011, 12:41 AM   #4
tommylovell
Member
 
Registered: Nov 2005
Distribution: Fedora, Redhat
Posts: 372

Rep: Reputation: 101Reputation: 101
I like rknichols explanation. It's better than mine, but i'll try to make up for it with a lack of brevity...

I don't have formal knowledge of this and probably don't have the terms right, but it's easy enough to do a few experiments and comment on them.

Just an 'ls' command shows the contents of the current directory.

Code:
[root@athlon ~]# ls -F
anaconda-ks.cfg  install.log.syslog  test                     tlpi-book/
home.iso         ps_mem.py*          tlpi-110706-book.tar.gz
install.log      swap*               tlpi-110706-dist.tar.gz
(The '-F' flag is just to tag an indicator onto the end of each directory entry listed: * is executable; / is a directory.)


When you list with an asterisk, 'ls *', it lists the current directory and goes one level deeper.

Code:
[root@athlon ~]# ls -F *
anaconda-ks.cfg  install.log.syslog  test
home.iso         ps_mem.py*          tlpi-110706-book.tar.gz
install.log      swap*               tlpi-110706-dist.tar.gz

tlpi-book:
acl/         filesys/              Makefile.inc.Tru64  psem/     syslim/
altio/       getopt/               memalloc/           pshm/     threads/
BUILDING     inotify/              mmap/               pty/      time/
cap/         lib/                  pgsjc/              README    timers/
CHANGES      libtlpi.a             pipes/              shlibs/   tty/
COPYING      loginacct/            pmsg/               signals/  users_groups/
daemons/     Makefile              proc/               sockets/  vmem/
dirs_links/  Makefile.inc          proccred/           svipc/    xattr/
filebuff/    Makefile.inc.FreeBSD  procexec/           svmsg/
fileio/      Makefile.inc.HP-UX    procpri/            svsem/
filelock/    Makefile.inc.MacOSX   procres/            svshm/
files/       Makefile.inc.Solaris  progconc/           sysinfo/

With a slash appended to a filename, it means "directory". (Like if you did a 'cp file directory/', it won't make a copy of "file" and call it "directory"; instead the slash forces 'cp' to make a file and place it into a directory called "directory".)

So 'ls */' says list off anything (*), but only if it is a directory (and go one level deep). So here we just get the contents of directory "tlpi-book".

Code:
[root@athlon ~]# ls -F */
acl/         filesys/              Makefile.inc.Tru64  psem/     syslim/
altio/       getopt/               memalloc/           pshm/     threads/
BUILDING     inotify/              mmap/               pty/      time/
cap/         lib/                  pgsjc/              README    timers/
CHANGES      libtlpi.a             pipes/              shlibs/   tty/
COPYING      loginacct/            pmsg/               signals/  users_groups/
daemons/     Makefile              proc/               sockets/  vmem/
dirs_links/  Makefile.inc          proccred/           svipc/    xattr/
filebuff/    Makefile.inc.FreeBSD  procexec/           svmsg/
fileio/      Makefile.inc.HP-UX    procpri/            svsem/
filelock/    Makefile.inc.MacOSX   procres/            svshm/
files/       Makefile.inc.Solaris  progconc/           sysinfo/
Now if you use the '-l' flag, you would get a long listing - typically with mode, owner, group, size, date.

Code:
[root@athlon ~]# ls -Fl */
total 420
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:16 acl/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:16 altio/
-rw-r--r--. 1 1000 1000   4911 Sep  1  2010 BUILDING
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:16 cap/
-rw-r--r--. 1 1000 1000   1677 Jul  6 07:45 CHANGES
-rw-r--r--. 1 1000 1000  34520 Mar 27  2010 COPYING
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:16 daemons/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:16 dirs_links/
drwxr-xr-x. 2 1000 1000   4096 Jul  6 07:47 filebuff/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:16 fileio/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:16 filelock/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:16 files/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:16 filesys/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:16 getopt/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:16 inotify/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:16 lib/
-rw-r--r--. 1 root root 162616 Aug  9 20:16 libtlpi.a
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:16 loginacct/
-rw-r--r--. 1 1000 1000    835 Jul  6 07:38 Makefile
-rw-r--r--. 1 1000 1000    704 Sep 13  2010 Makefile.inc
-rw-r--r--. 1 1000 1000    323 Feb 22  2010 Makefile.inc.FreeBSD
-rw-r--r--. 1 1000 1000    462 Feb 22  2010 Makefile.inc.HP-UX
-rw-r--r--. 1 1000 1000    318 Mar 27  2010 Makefile.inc.MacOSX
-rw-r--r--. 1 1000 1000    415 Feb 22  2010 Makefile.inc.Solaris
-rw-r--r--. 1 1000 1000    377 Feb 22  2010 Makefile.inc.Tru64
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:16 memalloc/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:16 mmap/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:16 pgsjc/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 pipes/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 pmsg/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 proc/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 proccred/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 procexec/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 procpri/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 procres/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 progconc/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 psem/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 pshm/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 pty/
-rw-r--r--. 1 1000 1000   4300 Jan 17  2011 README
drwxr-xr-x. 5 1000 1000   4096 Aug  9 20:17 shlibs/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 signals/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 sockets/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 svipc/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 svmsg/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 svsem/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 svshm/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 sysinfo/
drwxr-xr-x. 2 1000 1000   4096 Jul  6 07:47 syslim/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 threads/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 time/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 timers/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 tty/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 users_groups/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 vmem/
drwxr-xr-x. 2 1000 1000   4096 Aug  9 20:17 xattr/
And if you use the '-d' flag, it lists the directory, not its contents. From 'man ls',
Quote:
-d, --directory
list directory entries instead of contents, and do not derefer
ence symbolic links
Code:
[root@athlon ~]# ls -Fld */
drwxr-xr-x. 46 1000 1000 4096 Aug  9 20:16 tlpi-book//
This explanation is pretty unscientific, but it illustrates your question for others that might be reading this post.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need explanation how does the output comes????? immadisetty Programming 7 03-03-2010 04:11 AM
Error explanation igsen Linux - Newbie 2 04-08-2009 11:26 PM
Further explanation on symlink munichtexan Linux - Newbie 4 12-01-2005 11:52 AM
explanation on typedef naren Programming 5 03-09-2004 11:48 PM
I Could Use An Explanation winger Linux - General 3 04-13-2002 11:32 PM


All times are GMT -5. The time now is 10:44 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration