--- layout: page category_title: Basic commands category-page: basic tags: directory list author: Marinelli Alessandro title: LS previous-page: pages/cmd/basic/cd.html ---

The ls command is used to list a directory content or a file.
The name stands for LiSt.

Syntax

The default ls command syntax is:

ls [flags] [path]
Where [flags] are the ls flags, read below for more info,and [path] is the (optional) path (absolute or relative).If no path is provided the current directory is listed.

Usage


List the elements on the current working directory

Let's see how to show a list containing the elements included in the current working directory

  Device-name:Multimedia.Folder YourName$ ls
  Other Multimedia		This is a file,not a folder.jpg
  Photos				Videos

As you can see, typing ls in the Unix Shell, will give as output the list of elements contained in the actual working directory,which,in our case, is a folder named Multimedia.folder.
Elements listed can be files (look for exemple at the element This is a file,not a folder.jpg), such as other directories (look for example at the folder Photos ).

List the elements contained in a directory

    Device-name:Multimedia.Folder YourName$ ls Photos
    01.jpg		02.jpg
    03.jpg		04.jpg
  

As you can see, now the Unix Shell is showing us the elements contained in the folder Photos.

Notice: Photos is a valid path because it is actually the relative path of a folder contained in the current working directory.
You have to put the absolute path if you want to list elements which are not contained in the current working directory

Show hidden files

You can include hidden files (those which name starts with ".") in the displayed list using the -a flag

Device-name:Multimedia.Folder YourName$ ls -a Photos
.				01.png
..				02.png
.DS_Store			03.png
.secret.png			04.jpg
  

As you can see, now the SHELL shows more files for the same directory

Show list in long format

Device-Name:Photos YourName$ ls -l
total 10816
-rw-r--r--@ 1 YourName  YourGroup  3143706  4 Ott 13:28 01.png
-rw-r--r--@ 1 YourName  YourGroup  2269193 28 Ott 18:58 02.png
-rw-r--r--@ 1 YourName  YourGroup  37900   28 Ott 22:07 03.png
-rw-r--r--@ 1 YourName  YourGroup  75924   20 Ott 16:01 04.jpg

If the -l flag is given, the following information will be displayed for each file: file mode, number of links, owner name, group name, number of bytes in the file, abbreviated month, day-of-month file was last modi- fied, hour file last modified, minute file last modified, and the path- name. In addition, for each directory whose contents are displayed, the total number of 512-byte blocks used by the files in the directory is displayed on a line by itself, immediately before the information for the files in the directory.