UnixDroid

Files · Linux command

ls command in Linux

What does ls do?

ls lists the files and folders inside a directory. With -l it shows permissions, owner, size and date; with -a it also shows hidden files (names starting with a dot).

ls [options] [path…]

Most useful options

OptionWhat it does
-llong format: permissions, owner, size, date
-ashow hidden files too
-hhuman-readable sizes (K, M, G)
-Rlist sub-folders recursively
-tsort by modification time
-Ssort by size

ls examples

$ ls Try it ›

list the current folder

$ ls -la Try it ›

everything, including hidden files, in long format

$ ls -lh /var/log Try it ›

log files with readable sizes

$ ls -lt | head Try it ›

the 10 most recently changed files

In security work

After getting access to a machine, ls -la in home folders reveals hidden files like .bash_history and .ssh keys.

Questions about ls

How do I see hidden files in Linux?

Use ls -a (or ls -la for details). Hidden files are simply files whose names start with a dot.

What does drwxr-xr-x mean?

d = directory; rwx = the owner can read, write and enter it; r-x = the group and others can read and enter it but not change it.