theshell.ch/site/pages/cmd/basic/3-ls.html
bevilj af40908294 order pages for navigation
git-svn-id: svn+ssh://atelier.inf.usi.ch/home/bevilj/group-1@254 a672b425-5310-4d7a-af5c-997e18724b81
2018-11-18 20:38:56 +00:00

84 lines
2.5 KiB
HTML

---
layout: page
category-page: basic
category-title: Basic commands
tags: directory list
author: Alessandro Marinelli
title: ls
previous-page: pages/cmd/basic/2-closeshell.html
next-page: pages/cmd/basic/4-man.html
---
The <code>ls</code> command is used to list a directory content or a file.<br>
The name stands for <i>LiSt</i>.
The default ls command syntax is:
<pre>
ls [flags] [path]
</pre>
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.<br>
<h3>Usage</h3>
<h4>List the elements on the current working directory</h4>
Let's see how to show a list containing the elements included in the
current working directory
<pre>
ls
Other Multimedia my-cat.jpg
Photos Videos
</pre>
As you can see, typing <code>ls</code> in the Unix Shell, will give as output
the list of elements contained in the current working directory.<br>
Elements listed can be files (look for exemple at the element<i>my-cat.jpg</i>),
such as other directories (look for example at the folder <i>Photos</i>).<br><br>
<h3>List the elements contained in a directory</h3>
<pre>
ls Photos
01.jpg 02.jpg
03.jpg 04.jpg
</pre>
As you can see, now the Unix Shell is showing us the elements contained
in the folder <i>Photos</i>.<br><br>
<h3>Show hidden files</h3>
You can include hidden files (those which name starts with ".") in
the displayed list using the <code>-a</code> flag.
<pre>
ls -a Photos
. 01.png
.. 02.png
.DS_Store 03.png
.secret.png 04.jpg
</pre>
As you can see, now the shell shows more files for the same directory.<br><br>
<h3>Show list in long format</h3>
<pre>
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
</pre>
If the <code>-l</code> 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 modified,
hour file last modified, minute file last modified, and the path.
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.