How to List Files in a Directory in Linux
ls for a quick look, find for every file in every subdirectory: copy-paste examples for hidden files, files or folders only, sorting, counting, and saving the list.
Quick Answer
To list files in a directory in Linux, run ls (or ls -lah for hidden files, sizes and dates). To list every file in the directory and all its subdirectories, run find . -type f. Both are installed on every Linux distribution, and add > ~/files.txt to save the list.
Every command below works in Bash or Zsh on Ubuntu, Debian, Fedora, Arch and other distributions. Most also work on macOS; the exceptions are noted. On Windows, see our guides to listing files in CMD and PowerShell Get-ChildItem.
List Files with ls
ls lists the contents of one directory. With no argument it uses the current directory; pass a path to list another one, e.g. ls /etc or ls ~/Downloads.
| Option | What it does |
|---|---|
-l | Long format: permissions, owner, size, modified date, name. |
-a / -A | Include hidden (dot) files / same but without the . and .. entries. |
-h | Human-readable sizes (K, M, G) together with -l. |
-1 | One name per line (the default when output goes to a pipe or file). |
-t / -S | Sort by modified time (newest first) / by size (largest first). |
-r | Reverse the sort order, e.g. ls -ltr for oldest first. |
-R | Recurse into every subdirectory. |
-d | List the directory entry itself, not its contents. Used in ls -d */. |
# Everything here, hidden files included, with sizes and dates
ls -lah
# One name per line
ls -1
# Directories only
ls -d */
# Newest files first / largest files first
ls -lt
ls -lhSOptions can be combined in any order: ls -lah and ls -hal are the same. Run man ls for the full list.
List All Files in a Directory and Subdirectories with find
ls -R recurses, but it prints a separate block per directory with bare names, which is awkward to read, filter or save. find prints one path per line, which is what you usually want:
# Every file, all levels, relative paths
find . -type f
# Same, with absolute paths
find "$PWD" -type f
# Files in this directory only (no subdirectories)
find . -maxdepth 1 -type f
# Every directory, all levels
find . -type d
# Two levels deep only
find . -maxdepth 2 -type f
# Another directory
find /var/log -type ffind includes hidden files and hidden directories by default. To skip them, add -not -path '*/.*', for example find . -type f -not -path '*/.*'.
Filter and Sort the List
# Only PDFs, all subdirectories (case-insensitive)
find . -type f -iname '*.pdf'
# Several types at once
find . -type f \( -iname '*.jpg' -o -iname '*.png' \)
# Modified in the last 7 days
find . -type f -mtime -7
# Larger than 100 MB
find . -type f -size +100M
# 20 largest files, all levels (GNU find; Linux)
find . -type f -printf '%s\t%p\n' | sort -nr | head -20
# Find a file by part of its name
find / -type f -iname '*invoice*' 2>/dev/nullQuote the pattern ('*.pdf') so the shell passes it to find instead of expanding it first. -printf is a GNU extension: it works on Linux but not on the BSD find that ships with macOS. To filter by text in the path, pipe to grep: find . -type f | grep /archive/.
tree and du: Structure and Sizes
tree draws the directory hierarchy. It is not installed by default on most distributions: install it with sudo apt install tree (Debian/Ubuntu) or sudo dnf install tree (Fedora).
# Whole tree, hidden files included
tree -a
# Two levels deep, directories only
tree -L 2 -d
# Size of every file and directory, largest first
du -ah . | sort -rh | head -20du reports disk usage rather than exact byte size, so small files show as at least one block (often 4.0K). For exact sizes use ls -l or find -printf '%s'.
Save or Count the File List
# Save to your home directory (overwrite)
find . -type f > ~/files.txt
# Append to an existing list
find . -type f >> ~/files.txt
# List with modified dates and sizes (GNU find)
find . -type f -printf '%TY-%Tm-%Td %TH:%TM\t%s\t%p\n' > ~/files.tsv
# Count files, all levels / top level only
find . -type f | wc -l
find . -maxdepth 1 -type f | wc -lThe .tsv output opens cleanly in a spreadsheet: date, size in bytes and path in three tab-separated columns. Saving the list inside the directory you are listing makes the text file show up in its own output; writing to ~ avoids that.
Don't parse ls in scripts
File names can contain spaces and even newlines, which breaks loops over ls output. In scripts, use find . -type f -print0 | xargs -0 <command> or find . -type f -exec <command> {} +. On large scans, add 2>/dev/null to hide Permission denied messages; the listing is not affected.
When a File List Isn't Enough
A file list tells you which names exist. It can't tell you whether a copy matches the original: a backup can have every name and size right while one file is corrupted or an older version. You can go one step further with built-in tools and record a hash for every file:
# Record a SHA-256 hash for every file
find . -type f -print0 | xargs -0 sha256sum > ~/manifest.sha256
# Later, in the copy: check every file against it
sha256sum -c --quiet ~/manifest.sha256sha256sum -c reports changed and missing files, but not files that were added later. Our guide to verifying checksums with sha256sum covers the details, and comparing folders on Linux covers diff -rq and rsync dry runs.
FolderManifest does the same job with a report you can hand to someone else: every file with its path, size, dates and SHA-256 hash, exported as HTML, CSV or Markdown. Check a backup or migrated copy against it and it lists exactly which files were added, removed or changed. It runs locally on Linux, Windows 10/11 and macOS.
You may not need it
For a one-off list or a script, ls and find are the right tools. A manifest is worth it when you have to prove a copy is complete and unchanged, or check the same folder again next month.
Frequently Asked Questions
What is the command to list files in a directory in Linux?
ls. Run ls on its own for the current directory, or ls /path/to/dir for another one. Add -l for sizes, owners and dates, -a to include hidden files, and -h to show sizes as K, M and G.
How do I list all files in a directory and its subdirectories?
Run find . -type f. It prints the path of every file below the current directory, one per line, hidden files included. ls -R also recurses, but its grouped output is harder to read, filter or save.
How do I list only files, not directories?
For the current directory only, run find . -maxdepth 1 -type f. Drop -maxdepth 1 to include every subdirectory. ls -p | grep -v / works too for a quick look, but find handles odd file names safely.
How do I list only directories in Linux?
Run ls -d */ for the directories directly inside the current one, or find . -type d to list every directory at all levels.
How do I show hidden files with ls?
Use ls -a to show everything including the . and .. entries, or ls -A to show hidden files without them. find includes hidden files by default.
How do I count files in a directory in Linux?
Run find . -type f | wc -l to count every file in the directory tree, or find . -maxdepth 1 -type f | wc -l for the top level only. A file name containing a newline would be counted twice, which is rare in practice.
How do I save a file list to a text file?
Redirect the output: find . -type f > ~/files.txt. Writing to your home directory keeps the list out of its own output. Use >> to append instead of overwrite.
Go From a File List to Proof
Record every file with its SHA-256 hash, then check any later copy against it. Linux, Windows, and Mac. 7-day free trial, no card required, 30-day money-back guarantee.
