ls PDF Print E-mail

ls

This command will list the contents of a directory.


Example, this will list contents of current working directory:


ls -l


Options

-l list files one line at a time

-A lists all the contents of a directory except for current directory and parent directory

-B ignore backups

-c sort by change time

-d lists file and directory names without contents

-e lists all times in full

-f lists without sorting

-k lists file size in kilobytes

-l lists files in long format

-L list files by symbolic link

-m list files horizontally separated by commas

-r sorts files in reverse order

-R lists files recursively

-S lists files by size, biggest first

-u sorts files by the last time they were accessed

-x prints in columns, sorted horizontally

-X sorts files alphabetically by file extension



To list the contents of the present working directory type:

ls


data n1.png sandisk256_mini.jpg

Desktop n20.png sed-scripts.sxw

dsl-scripts.sxw n21.png u1.png

focus n2.png u2.png

focus1.png n3.png u3.png

focus2.png n4.png ub1.png

focus3.png n7.png ub3.png


Notice you have 3 columns listing files and images. Now try the same thing with the -l option.


ls -l


-rw-r--r-- 1 mike mike 1756 2005-07-29 09:22 data

drwxr-xr-x 4 mike mike 4096 2005-07-29 05:45 Desktop

-rw-r--r-- 1 mike mike 7895 2005-07-29 05:51 dsl-scripts.sxw

drwxr-xr-x 2 mike mike 4096 2005-07-31 09:12 focus

-rw-r--r-- 1 mike mike 608529 2005-07-04 00:45 focus1.png

-rw-r--r-- 1 mike mike 630219 2005-07-04 00:45 focus2.png

-rw-r--r-- 1 mike mike 367726 2005-07-04 00:46 focus3.png

-rw-r--r-- 1 mike mike 630219 2005-07-04 00:49 focus6.png

drwxr-xr-x 7 root root 4096 2005-03-04 06:15 jre1.5.0_02
---cut---

When you list with the -l option you get more information and it is placed on one line. The information you will receive is permissions, owner, group file size, time last modified and file name.


If you had a large list of material and you wanted to list it by the time the file was changed you could use the -c option.


ls -c


focus

focus1.png

focus2.png

focus3.png

focus6.png


The most recently changed file is first.


To list all files and directories without any kind of formating choose the -f option.


ls -f


.

..

.bashrc

.bash_profile

.Xauthority

.xsession-errors

.dmrc

.gconf

focus.png

---cut---


Note that the -f will also list the hidden files and directories which start with a period.


List all files horizontally only separated with a comma, ls -m


Desktop, dsl-scripts.sxw, focus, focus1.png,

focus2.png, focus3.png, focus6.png, jre1.5.0_02,

jre-1_5_0_02-linux-i586.bin,

jre-1_5_0_02-linux-i586-rpm.bin, n10.png, n12.png,
---cut---


List files by size with the biggest first.


ls -S


jre-1_5_0_02-linux-i586.bin

jre-1_5_0_02-linux-i586-rpm.bin

ub6.png

u3.png

up1.png

ub1.png

ub3.png

---cut---


Sort files by the last time they were accessed. Use this command:

ls -u


Andrew.sxc

focus6.png

focus3.png

focus2.png

focus1.png

focus

Desktop