Skip to content

ls

19 commands

Lists directory contents with sizes, permissions, owners, timestamps and hidden files.

  • files
  • directories

Install ls

sudo apt install coreutils

Basics6

ls

Lists the visible files and folders in the current directory.

ls <path>

Lists the contents of another directory without changing into it.

Link
ls -la

Long listing of everything, including hidden dot-files: permissions, link count, owner, group, size and modification time.

Link
ls -lh

Long listing with human-readable sizes (K, M, G) instead of bytes.

Link
ls -1

Prints one name per line — handy when piping into other commands.

ls -d */

Lists only the directories in the current folder.

Sorting4

ls -lt

Sorts by modification time, newest first. Add -r to reverse.

ls -ltr /tmp

Oldest first — the most recently changed files end up at the bottom, next to your prompt.

Link
ls -lS

Sorts by file size, largest first.

ls -lX

Groups files by extension (GNU ls).

Link

Details6

ls -i

Shows inode numbers — useful for spotting hard links and deleting files with awkward names.

Link
ls -ln

Shows numeric UIDs and GIDs instead of names — reveals files owned by deleted users.

Link
ls -l --time-style=full-iso

Shows full timestamps with seconds and timezone, useful when building a forensic timeline.

Link
ls -lu

Shows (and with -t, sorts by) last access time instead of modification time.

Link
ls -lR <path>

Lists a directory tree recursively.

Link
ls -la --color=auto

Colours files by type; most distributions alias ls to this already.

Link

Security checks3

ls -la /root

Checks whether the root home directory is readable by your user — it should not be.

Link
ls -l /etc/passwd /etc/shadow

Verifies permissions on the account files: passwd should be 644, shadow 640 or stricter. A world-readable shadow is a serious finding.

Link
ls -la /etc/cron*

Lists cron directories and files to find scheduled jobs and check who can modify them.

Link