Ls

ls (list) is used to print the contents of a directory out to a screen.

Contents

[edit] 1 Examples

[edit] 1.1 List the contents of a current directory

ls

[edit] 1.2 List the contents of a given directory

This command will list out all files and directories in the directory dir1:

ls dir1

[edit] 1.3 List all files of a certain type

This example command using wildcards will list out all files in the current directory of ending with .fasta:

ls *.fasta

[edit] 1.4 Getting more information than the filename

The -l option will use the long format. The list will now be a table of information about each item in the directory:

Column 1 will have the permissions and file type.

Column 2 will have the number of subdirectories. If this is a file and not a directory, the value will be one. If the item is a directory, then the number will be 2 or greater. (All directories have two "pretend" directories: "." pointing to the directory itself and ".." pointing to the parent directory.) To find the number of actual subdirectories, subtract this number by 2.

Column 3 will be the owner of the file. This will probably be your username!

Column 4 will be the group the file belongs to.

Column 5 will be the size of the file. If you are interested in the file size information, use ls -lh to get the file size in human readable form, like 153K for 153 kilobytes or 1.4M for 1.4 megabytes. If the item is a directory, this number will NOT indicate the size of all of that directories contents. For that, use du.

Columns 6-8 will be the date of the file or directory. This stands for the last time the file was modified. If you want to update that value, you can use touch filename.

Column 9 will be the name of the file or directory.

[edit] 1.5 Listing all the contents of a directory, including subdirectories

This will recursively list the contents of a directory, then the contents of all subdirectories, then the contents of all of THEIR subdirectories, so on and so forth:

ls -R directory
XHTML 1.1 CSS 2 Sec 508