-5

When I try the command ls with -aF option inside any directory whether it's empty or not, I always got the following:

./  ../ 

so what does the output mean when I have these two options together with ls command?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
redRose
  • 83
  • 1
  • 3
  • 10
  • 1
    Please take a look at: `man ls` – Cyrus Oct 01 '16 at 11:11
  • I understand that -a for showing hidden files and -F for identifying the file type but I didn't get it when I add these two options together? @Cyrus – redRose Oct 01 '16 at 11:21
  • 1
    See: [What is double dot(..) and single dot(.) in Linux?](http://stackoverflow.com/q/23242004/3776858) – Cyrus Oct 01 '16 at 11:33
  • You don't get why the two directory entries present in all directories are marked as directories? – chepner Oct 01 '16 at 11:52
  • ./ is the current directory and ../ is the previous diectory – mohsen.b Oct 01 '16 at 12:12
  • @chepner yes. I know that ./ means current directory and ../ is the parent directory. But why I have them even if the directory is not empty and there are some files and folders inside this directory? – redRose Oct 01 '16 at 12:44
  • Why do you think they would only appear in an empty directory? – chepner Oct 02 '16 at 13:14

1 Answers1

1

When you use ls, you are reading a directory file, not actually looking in a directory. Every directory listing contains an entry for the present/current directory, as well as its parent directory, just as you would expect to also see listings for sub/child directories in any directory listing.

The -A option for ls merely tells ls to display ALL files, which includes the entries of ./ & ../ for present and parent. Note that these dots are merely a shorthand that the shell (bash) uses to represent file paths for those files. In other words, what "./" really means is say ~/Desktop if you were currently in the Desktop directory doing an ls. And "../" would mean "~/" which is just another symbolic shorthand to represent your user home directory, which is probably something like /Users/your_username on macOS (OS X), or /usr/your_username for various Linux distributions. Note that those paths could also be written with the forward slash appended at the end and would mean the same thing (e.g., /Users/your_username/ is the same as /Users/your_username because they are both references to other directories (directory files).

Use the -a option for ls if you don't want to see ./ & ../, but still want to see (other) hidden files.

Using the -F option causes ls to display appended characters to the file types based on the file type. This is why directories are displayed with the forward slash appended at the end, and executables are displayed as executable* (with the asterisk appended), and regular files have no appendage (e.g., .txt, .png, .dmg).

GH05T
  • 145
  • 1
  • 7