ls command in Linux: list directory contents
Updated November 1, 2026
The ls command shows what is in a directory: its files and subdirectories.
Syntax
ls [options] [path]With no arguments ls prints the current directory.
Common cases
ls # the current directory
ls -l # long format: permissions, owner, size, date
ls -a # show hidden files too (names that start with a dot)
ls -lh # human-readable sizes: K, M, G
ls -lt # sort by time, newest firstSample output
$ ls
docs notes.txt report.log
$ ls -l
total 2408
drwxrwxr-x 2 student student 4096 Jul 26 12:13 docs
-rw-rw-r-- 1 student student 45 Jul 26 12:13 notes.txt
-rw-rw-r-- 1 student student 2457600 Jul 26 12:13 report.log
$ ls -lh report.log
-rw-rw-r-- 1 student student 2.4M Jul 26 12:13 report.logHow it works: what a hidden file is
Linux has no separate 'hidden' attribute. A file is hidden simply because its name starts with a dot, for example
.bashrc.lsdoes not print those by default, whilels -aprints everything.
Try it
Open the sandbox: a real throwaway Linux terminal in your browser. Run the commands above by hand. The container is deleted when you leave, so there is nothing to be afraid of breaking.
Where this is in the book: the chapter The filesystem and moving around.
Common mistakes
The total 2408 line at the top of ls -l is not bytes and not the sum of the size column. It counts disk blocks in units of one kilobyte, and only for the entries that made it into the output. The sizes in that same listing add up to 2461741 bytes. That is also why a directory holding nothing but dotfiles reports total 0: ls -l never listed them, so it never counted them.
The size column of a directory says nothing about how much data is inside. ls -ld docs prints 4096, the size of the directory entry itself. Put a 5 MB file in there and ls -ld docs still prints 4096, while du -sh docs prints 4.8M. du is what measures a directory.
ls prints columns only to a terminal. The moment the output goes into a pipe or a file, the format changes to one name per line: ls gives a.txt b.txt notes.md on one line, and ls | cat gives three lines. A script sees something different from what you see, which is why parsing the output of ls in scripts is a bad idea.