Beginner · 8 min · practise every command in the built-in terminal

ls — List Directory Contents

ls shows you what's in a directory.

Basic usage

ls

Shows files in the current directory.

Common flags

ls -l      # Long format (permissions, size, date)
ls -a      # Show hidden files (starting with .)
ls -la     # Both combined
ls -lh     # Human-readable file sizes (KB, MB)
ls -lt     # Sort by modification time
ls -lr     # Reverse order
ls -R      # Recursive (show subdirectories)

List a specific directory

ls /etc
ls /var/log
ls ~/documents

Understanding ls -la output

-rw-r--r-- 1 student student  42 Jan 15 10:30 hello.txt
drwxr-xr-x 2 student student 4096 Jan 15 10:00 documents
  • First character: - = file, d = directory, l = symlink
  • Next 9 characters: permissions (rwxrwxrwx)
  • Number: hard link count
  • Owner, group
  • File size in bytes
  • Date modified
  • Filename

Practice tasks

  1. List all files in your home directory (including hidden ones)
  2. List the contents of /etc directory
  3. List files with human-readable sizes
  4. List files sorted by modification time
  5. Recursively list your home directory and its subdirectories

Commands in this lesson

Navigation