Your home directory holds more files than ls shows: some names are hidden. One option shows every name, another shows details about each.
ls lists a directory's contents: with no path, the current one; with a path, the one you name. Names that start with a dot are left out by ls — these are hidden names. Settings files are usually named this way, such as .bashrc in your home directory. You can read a hidden file like any other.
The -a option shows every name, including . and ... The -l option prints a detailed list: type, permissions, owner, size, and modification time. Options can be joined: -la does both at once.
The dot names — .bashrc, .profile — appear only in the second and third output. In the third, each name gets its own line. The first line, total, is the disk space these files take up. After it, the first character of a line is the type: d for a directory, - for a regular file. A separate lesson covers permissions and owners.
A colleague says the project directory holds .env, but ls shows only site.conf there. Which command do you use to check whether .env is there?
-
pwdprints the path of the current directory.lslists the names in a directory, and hidden ones with-a. -
The dot is the same current directory, so
ls .shows the same list, without hidden names. -
-ladds details to the same names and does not show hidden ones. The-aoption lists every name.
ls without options leaves out names that start with a dot, so .env is not in the list. ls -a lists every name, .env included, if the file is there.
Key points
-
ls -ashows hidden names too — the ones that start with a dot. -
In
ls -l, the first character of a line is the type:dfor a directory,-for a file.