Wednesday 5 October 2011

List Directory Contents

ls - command used to list contents of our current directory.
Example:
jp@ubuntu:~$ ls
cpgms      Downloads         Music      Public     Untitled Document 1
Desktop    examples.desktop  Pictures   Templates  Videos
Documents  jp.txt            print.pdf  test.c
(Directory names are in Bold characters and remaining are file names)


% ls <Directory name>: Lists all directory contents.  If directory name is not given, it will list the contents of current directory.
Example:
jp@ubuntu:~$ ls cpgms
anand  dennis  ex01.c  ex02.c  fib.c  jp.c  lib  lssort.c  mat.c  pointers  rhombus.c


% ls -a <directory name>:  Lists all the contents in a directory, including hidden files whose name begins with dot.
Example:
jp@ubuntu:~$ ls -a cpgms
.  ..  anand  dennis  ex01.c  ex02.c  fib.c  jp.c  lib  lssort.c  mat.c  pointers  rhombus.c


% ls  -l <directory name>: Lists contents of the directory in long format, which includes permissions, hard link count, owner, group,  modification date and file name.
Example:
jp@ubuntu:~$ ls -l cpgms
total 44
drwxr-xr-x 3 jp jp 4096 2011-08-13 09:54 anand
drwxr-xr-x 3 jp jp 4096 2011-01-22 22:50 dennis
-rw-r--r--    1 jp jp     72 2009-10-24 07:15 ex01.c
-rw-r--r--    1 jp jp     91 2009-10-26 06:45 ex02.c
-rw-r--r--    1 jp jp   185 2009-10-25 13:06 fib.c
-rw-r--r--    1 jp jp     80 2011-02-15 20:50 jp.c
drwxr-xr-x 2 jp jp 4096 2011-02-15 20:50 lib
-rw-r--r--    1 jp jp 2249 2009-10-28 19:02 lssort.c
-rw-r--r--    1 jp jp  288 2009-10-25 13:18 mat.c
drwxr-xr-x 2 jp jp 4096 2011-08-07 11:13 pointers
-rw-r--r--    1 jp jp   179 2009-11-02 19:26 rhombus.c


% ls -R <directory name>: Recursively lists sub directories.
Example:
jp@ubuntu:~$ ls demo
ls  rm
jp@ubuntu:~$ ls -R demo
demo:
ls  rm
demo/ls:
a.c
demo/rm:
a.c









No comments:

Post a Comment