1

First look at the output of ls --help command:

Several lines ignored in the output

-a, --all                  do not ignore entries starting with .
-l                         use a long listing format
  1. As you can see -a and -all should be same
  2. I found -l flag but there is no -al in the help but this flag works

So my questions are:

  1. Why don't -a and -all return the same output but help shows both of them in a same line?
  2. Is -al an old form of -all because both are the same but I didn't find manual for -al
  3. What's the meaning of . .. in the ls -a output?

Outputs of above commands included below:

ls -a :

.  ..  article.png  bgame  newtest

ls -all :

total 32
drwxr-xr-x  4 shahab shahab  4096 Sep 19 12:15 .
drwxrwxr-x 33 shahab sudo    4096 Oct 28 16:00 ..
-rw-r--r--  1 shahab shahab 15504 Aug 19 16:06 article.png
drwxr-xr-x  5 shahab shahab  4096 Aug 19 10:41 bgame
drwxr-xr-x  5 shahab shahab  4096 Aug 29 16:48 newtest

ls -al :

total 32
drwxr-xr-x  4 shahab shahab  4096 Sep 19 12:15 .
drwxrwxr-x 33 shahab sudo    4096 Oct 28 16:00 ..
-rw-r--r--  1 shahab shahab 15504 Aug 19 16:06 article.png
drwxr-xr-x  5 shahab shahab  4096 Aug 19 10:41 bgame
drwxr-xr-x  5 shahab shahab  4096 Aug 29 16:48 newtest
Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
Shahab Ouraie
  • 45
  • 2
  • 9

1 Answers1

7

You’re missing the extra hyphen: ls -a is the same as ls --all, with two hyphens.

ls -all, with a single hyphen, is the same as ls -a -l -l, which is the same as ls -a -l, which is the same as ls -al.

A single - introduces short options, which are single characters, and can be combined. Two -s introduce long options, which are words (or multiple words) and can’t be combined.

In the ls -a output, . represents the current directory, and .. represents the parent directory.

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
  • tnx in advance sir. so one more question is whats the meaning of add a same flag **`-l`** 3 times? of course each time you copy-paste this flag it wont add more details on output because as you said **`ls -a -l -l`** same as **`ls -a -l`** also am I understood true that, you can combine two flags by type one hyphen and then both flags? .e.g **`-a`** + **`-b`** = **`-ab`** ?? (thanks again) – Shahab Ouraie Oct 28 '19 at 17:16
  • sorry, since I'm a beginner, I love learning by asking! 2nd question is: are there 2 files in every directory, one for current directory **`.`** one for parent directory **`..`** what are they using for? – Shahab Ouraie Oct 28 '19 at 17:38
  • Adding `-l` more than once doesn’t make any difference (unlike other programs where some options increase their effect if they’re added more than once). Two flags can indeed be combined, `-a` and `-b` becomes `-ab`. – Stephen Kitt Oct 28 '19 at 17:39
  • really thanks for this **best answering** – Shahab Ouraie Oct 28 '19 at 17:45
  • Yes, each directory in a POSIX file system contains `.` and `..`. To understand `..`, see [this question](https://unix.stackexchange.com/q/541779/86440) and its answers, and the linked questions. `.` provides a reference to the current directory in a generic way. – Stephen Kitt Oct 28 '19 at 17:47