TExcelTAD
Home › Terminal & Command Line › Listing Files

Listing Files

Looking at what's in a folder is the command you'll type most often. CMD has dir, PowerShell has Get-ChildItem (with the aliases dir, gci and, on Windows, ls), and Linux and macOS have ls. All three can show names only, details, hidden files, sub-folders and sorted lists.

Task CMD PowerShell bash / zsh
List the current folder dir Get-ChildItem (dir, gci) ls
Names only dir /b Get-ChildItem -Name ls -1
Details (size, date) dir Get-ChildItem ls -l, ls -lh
Include hidden files dir /a Get-ChildItem -Force ls -a (-A without . ..)
Only folders / only files dir /a:d / dir /a:-d -Directory / -File ls -d */ / zsh *(.)
Include sub-folders dir /s -Recurse ls -R, find ., tree
Sort by size / date dir /o:s / dir /o:d Sort-Object Length / LastWriteTime ls -S / ls -t
Reverse order /o:-n, /o:-s Sort-Object … -Descending ls -r
One pattern dir *.txt Get-ChildItem *.txt ls *.txt

Each example below builds the same small website folder first:

text
shop/
├── .env           (a "dot file")
├── img/
│   └── logo.png
├── index.html
└── style.css

Windows (CMD)

The full dir listing shows a header with the volume, one line per entry with date, time, <DIR> or the size, and a summary. Here's what it looks like on Windows (sample output — dates, serial number and free space will differ):

cmd
C:\Users\ada\shop>dir
 Volume in drive C is Windows
 Volume Serial Number is 6C2A-91F3

 Directory of C:\Users\ada\shop

12/03/2026  09:41    <DIR>          .
12/03/2026  09:41    <DIR>          ..
12/03/2026  09:41                 9 .env
12/03/2026  09:41    <DIR>          img
12/03/2026  09:41                13 index.html
12/03/2026  09:41                 8 style.css
               3 File(s)             30 bytes
               3 Dir(s)  182,315,909,120 bytes free

Options make it more useful. /b (bare) prints names only, /o:n sorts by name, /s includes sub-folders with full paths, and /a: filters by attribute (d directory, -d not a directory, h hidden):

cmd · try it yourself
@echo off
mkdir shop\img
cd shop
echo body{}> style.css
echo ^<h1^>Hi^</h1^>> index.html
echo PNG> img\logo.png
echo SECRET=1> .env
dir /b /o:n
echo --- files only:
dir /b /o:n /a:-d
echo --- with sub-folders:
dir /b /o:n /s
echo --- largest first:
dir /b /o:-s /a:-d
.env
img
index.html
style.css
--- files only:
.env
index.html
style.css
--- with sub-folders:
C:\Users\learner\shop\.env
C:\Users\learner\shop\img
C:\Users\learner\shop\index.html
C:\Users\learner\shop\style.css
C:\Users\learner\shop\img\logo.png
--- largest first:
index.html
.env
style.css

On Windows a leading dot doesn't hide a file: hidden files have the hidden attribute instead (set with attrib +h), and dir skips them unless you add /a. Setting DIRCMD=/o:n in your environment makes every dir sort by name.

Windows (PowerShell)

Get-ChildItem returns objects, so you choose which properties to show and how to sort, instead of parsing text:

powershell · try it yourself
New-Item -ItemType Directory shop/img -Force | Out-Null
Set-Location shop
Set-Content style.css 'body{}'
Set-Content index.html '<h1>Hi</h1>'
Set-Content img/logo.png 'PNG'
Set-Content .env 'SECRET=1'

Get-ChildItem -Name
'--- including hidden:'
Get-ChildItem -Force -Name
'--- recursive:'
Get-ChildItem -Recurse -File -Name
'--- by size:'
Get-ChildItem -File | Sort-Object Length -Descending | Format-Table Name, Length
img
index.html
style.css
--- including hidden:
img
.env
index.html
style.css
--- recursive:
index.html
style.css
img/logo.png
--- by size:

Name       Length
----       ------
index.html     12
style.css       7

The playground runs on Linux, where PowerShell follows the Unix rule that names starting with . are hidden, so .env appears only with -Force. On Windows it uses the hidden attribute, like dir. The default table view (Get-ChildItem without -Name) shows Mode, LastWriteTime, Length and Name columns; Mode letters are d (directory), a (archive), r (read-only), h (hidden), s (system) and l (link).

Linux & macOS (bash/zsh)

ls hides names starting with a dot unless you pass -a (shows . and .. too) or -A. -F marks folders with /, -R recurses, and -1 forces one name per line:

bash · try it yourself
mkdir -p shop/img && cd shop
echo 'body{}' > style.css
echo '<h1>Hi</h1>' > index.html
echo PNG > img/logo.png
echo SECRET=1 > .env

ls
echo "--- all:"
ls -A
echo "--- classified, recursive:"
ls -FR
echo "--- by size:"
ls -S
img
index.html
style.css
--- all:
.env
img
index.html
style.css
--- classified, recursive:
.:
img/
index.html
style.css

./img:
logo.png
--- by size:
img
index.html
style.css

Sizes and dates come from ls -l ("long" listing): permissions, link count, owner, group, size in bytes, modification time and name. -h prints sizes as 4.0K, 1.2M. To keep the output identical on every run, this example sets the file dates with touch -d. Notice that ls -l shows the year instead of the time for files older than six months:

bash · try it yourself
mkdir shop && cd shop
printf 'body{}\n' > style.css
printf '<h1>Hi</h1>\n' > index.html
touch -d '2025-03-12 09:41' style.css index.html
ls -l
total 8
-rw-r--r-- 1 learner learner 12 Mar 12  2025 index.html
-rw-r--r-- 1 learner learner  7 Mar 12  2025 style.css

tree (preinstalled on many Linux systems, brew install tree on macOS) draws the hierarchy:

bash · try it yourself
mkdir -p shop/img && touch shop/index.html shop/style.css shop/img/logo.png
tree shop
shop
├── img
│   └── logo.png
├── index.html
└── style.css

2 directories, 3 files

zsh glob qualifiers

zsh can filter a listing while matching names, with glob qualifiers in parentheses: (/) folders, (.) plain files, (.L+10) files larger than 10 bytes, (om) newest first. **/ searches all sub-folders:

zsh · try it yourself
mkdir -p shop/img && cd shop
print 'body{}' > style.css
print '<h1>Hi</h1>' > index.html
print PNG > img/logo.png
print -l *(/)
print -- ---
print -l *(.)
print -- ---
print -l **/*(.)
print -- ---
print -l *(.L+10)
img
---
index.html
style.css
---
img/logo.png
index.html
style.css
---
index.html

macOS differences

macOS's ls is the BSD version. Common options (-l -a -A -F -R -S -t -r -h -1) are the same, but GNU-only options such as --color=auto or --group-directories-first don't exist; colours come from ls -G instead. More in BSD vs GNU Tools.

zsh
ada@macbook shop % ls -lG
total 16
drwxr-xr-x  3 ada  staff  96 Mar 12 09:41 img
-rw-r--r--  1 ada  staff  12 Mar 12 09:41 index.html
-rw-r--r--  1 ada  staff   7 Mar 12 09:41 style.css

Learn more: ls: List Files · cd & dir · PowerShell Files & Folders

Test yourself

Which CMD command lists only file names, sorted by name, including sub-folders?

  1. dir /s /b /o:n
  2. dir -R
  3. ls /s
  4. dir /a:d

Why doesn't ls show .env?

  1. Files without an extension are skipped
  2. On Linux and macOS, names starting with a dot are hidden unless you use -a or -A
  3. .env is a folder
  4. ls only lists files you created today

In PowerShell, how do you list only folders?

  1. Get-ChildItem -Directory
  2. Get-ChildItem /a:d
  3. ls -d */
  4. Get-ChildItem -Folder