Skip to content

File Listing

Every command on this page returns typed PowerShell objects. Terminal output looks like bash, but you can access properties like .SizeBytes, .Permissions, and .IsDirectory directly.


List directory contents.

ls [flags] [path...]
FlagDescription
-lLong listing with permissions, owner, size, and date
-aShow hidden files (names starting with .)
-hHuman-readable sizes (4.0K, 1.2M) in long listing
-RRecurse into subdirectories
-SSort by file size (largest first)
-tSort by modification time (newest first)
-rReverse the sort order
-1One entry per line
PropertyTypeDescription
NamestringFile or directory name
FullPathstringAbsolute path on disk
IsDirectorybool$true for directories
SizeByteslongSize in bytes (4096 for directories)
PermissionsstringUnix-style permission string (e.g., -rw-r--r--)
LinkCountintNumber of hard links
OwnerstringFile owner name
GroupstringFile group name
LastModifiedDateTimeLast modification time
BashTextstringFormatted terminal output

List files with details:

Terminal window
ls -la
drwxr-xr-x 5 beagle beagle 4096 Apr 2 10:30 .
drwxr-xr-x 3 beagle beagle 4096 Apr 1 09:15 ..
-rw-r--r-- 1 beagle beagle 1084 Apr 2 10:30 README.md
drwxr-xr-x 2 beagle beagle 4096 Apr 2 10:28 src

Sort by size, human-readable:

Terminal window
ls -lSh
-rw-r--r-- 1 beagle beagle 141K Apr 2 10:30 PsBash.psm1
-rw-r--r-- 1 beagle beagle 1.1K Apr 2 10:28 PsBash.psd1
-rw-r--r-- 1 beagle beagle 512 Apr 1 09:15 README.md

Access typed properties:

Terminal window
$files = ls -la
$files[0].Name # "README.md"
$files[0].SizeBytes # 1084
$files[0].Permissions # "-rw-r--r--"
$files[0].LastModified # 04/02/2026 10:30:00

Pipeline: filter and sort while preserving objects:

Terminal window
$scripts = ls -la | grep '.ps1' | sort -k5 -h
$scripts[0].Name # "PsBash.psm1"
$scripts[0].SizeBytes # 141234

Recursive listing with reverse time sort:

Terminal window
ls -laRtr src/

Search for files in a directory hierarchy.

find [path] [predicates...]
FlagArgumentDescription
-namepatternGlob pattern to match file names (e.g., '*.ps1')
-typef or dFilter by type: f for files, d for directories
-sizeexprSize filter: +1M (larger than 1 MB), -500c (smaller than 500 bytes). Suffixes: c bytes, k KiB, M MiB, G GiB. No suffix = 512-byte blocks
-maxdepthNDescend at most N levels below the start path
-mtimeexprModification time in days: -7 (within last 7 days), +30 (more than 30 days ago)
-emptyMatch empty files (0 bytes) and empty directories
PropertyTypeDescription
PathstringDisplay path relative to search root (e.g., ./src/main.ps1)
NamestringFile or directory name
FullPathstringAbsolute path on disk
IsDirectorybool$true for directories
SizeByteslongSize in bytes
PermissionsstringUnix-style permission string
LinkCountintNumber of hard links
OwnerstringFile owner name
GroupstringFile group name
LastModifiedDateTimeLast modification time
BashTextstringDisplay path (same as Path)

Find all PowerShell files:

Terminal window
find . -name '*.ps1'
./src/PsBash.psm1
./tests/PsBash.Tests.ps1

Find large files:

Terminal window
find . -type f -size +1M

Find recently modified directories:

Terminal window
find . -type d -mtime -7

Combine with pipeline for typed access:

Terminal window
$bigFiles = find . -type f -size +100k
$bigFiles | ForEach-Object { "$($_.Name): $($_.SizeBytes) bytes" }

Limit search depth and find empty files:

Terminal window
find . -maxdepth 2 -empty

Display file or file system status.

stat [flags] file...
FlagArgumentDescription
-cformatFormat string using % specifiers (see table below)
-tTerse output: single line of space-separated values
--printfformatLike -c but interprets escape sequences (\n, \t) and does not append a trailing newline
SpecifierValue
%sSize in bytes
%aOctal permissions (e.g., 0644)
%AHuman-readable permissions (e.g., -rw-r--r--)
%nFile name
%NFull path
%UOwner name
%GGroup name
%iInode number
%bNumber of 512-byte blocks
%dDevice number
%YModification time as Unix epoch
%hNumber of hard links
%%Literal %
PropertyTypeDescription
NamestringFile name
FullPathstringAbsolute path
IsDirectorybool$true for directories
SizeByteslongSize in bytes (4096 for directories)
PermissionsstringUnix-style permission string
OctalPermsstringOctal permission string (e.g., 0644)
LinkCountintHard link count
OwnerstringOwner name
GroupstringGroup name
InodelongInode number (0 on Windows)
BlockslongNumber of 512-byte blocks
DevicelongDevice number
LastModifiedDateTimeLast modification time
MtimeEpochlongModification time as Unix epoch seconds
AccessTimeDateTimeLast access time
AtimeEpochlongAccess time as Unix epoch seconds
BashTextstringFormatted output

Default output:

Terminal window
stat README.md
File: README.md
Size: 1084 Blocks: 8 IO Block: 4096 regular file
Device: 0 Inode: 12345 Links: 1
Access: (0644/-rw-r--r--) Uid: (beagle) Gid: (beagle)
Modify: 2026-04-02 10:30:00.0000000 -07:00

Custom format — size and name:

Terminal window
stat -c '%s %n' README.md
1084 README.md

Terse mode:

Terminal window
stat -t README.md

Access typed properties:

Terminal window
$info = stat README.md
$info.SizeBytes # 1084
$info.OctalPerms # "0644"
$info.MtimeEpoch # 1743530400
$info.Owner # "beagle"

Printf with escape sequences:

Terminal window
stat --printf='%n\t%s\n' README.md src/

List contents of directories in a tree-like format with box-drawing characters.

tree [flags] [path]
FlagArgumentDescription
-aShow hidden files (names starting with .)
-dList directories only
-LNDescend at most N levels deep
-IpatternExclude files matching glob pattern
--dirsfirstSort directories before files at each level
PropertyTypeDescription
NamestringFile or directory name (empty for summary line)
PathstringPath relative to tree root
DepthintNesting depth (0 for root and summary)
IsDirectorybool$true for directories
TreePrefixstringBox-drawing prefix characters
BashTextstringFull formatted line with prefix and name

Show directory tree:

Terminal window
tree src/
src
├── PsBash.Format.ps1xml
├── PsBash.psd1
└── PsBash.psm1
0 directories, 3 files

Limit depth:

Terminal window
tree -L 2 .

Directories only, directories first:

Terminal window
tree -d --dirsfirst .

Filter typed entries from the pipeline:

Terminal window
$entries = tree src/
$dirs = $entries | Where-Object { $_.IsDirectory -and $_.Name -ne '' }
$dirs.Name # list of directory names

Exclude patterns:

Terminal window
tree -I 'node_modules' -L 3 .

Estimate file space usage.

du [flags] [path...]
FlagArgumentDescription
-hHuman-readable sizes (4.0K, 1.2M)
-sSummarize: show only the total for each argument
-aShow sizes for individual files, not just directories
-cProduce a grand total line at the end
-dNMax depth of directory reporting
PropertyTypeDescription
SizelongSize in KiB (ceiling)
SizeByteslongExact size in bytes
SizeHumanstringHuman-readable size string
PathstringDisplay path
DepthintDirectory depth relative to target
IsTotalbool$true for the grand total line (-c)
BashTextstringFormatted size\tpath output

Summarize current directory:

Terminal window
du -sh .
1.2M .

Show all files with human-readable sizes:

Terminal window
du -ah src/

Limit depth and show grand total:

Terminal window
du -hc -d 1 .
140K ./src
32K ./tests
8.0K ./docs
180K .
180K total

Access typed sizes for computation:

Terminal window
$usage = du -a src/
$totalBytes = ($usage | Measure-Object -Property SizeBytes -Sum).Sum
"Total: $totalBytes bytes"

Find largest subdirectories:

Terminal window
du -d 1 . | sort -k1 -rn | head 5

Print name of current/working directory.

pwd [flags]
FlagDescription
-PPrint the physical directory path (resolve symlinks via the OS)

Without -P, pwd returns the PowerShell logical path from Get-Location. With -P, it calls [System.IO.Directory]::GetCurrentDirectory() to resolve symlinks.

PropertyTypeDescription
BashTextstringWorking directory path with forward slashes

Print working directory:

Terminal window
pwd
/home/beagle/work/project

Physical path (resolve symlinks):

Terminal window
pwd -P

Store and use in pipeline:

Terminal window
$cwd = pwd
"Working in: $cwd"

Strip directory and suffix from filenames.

basename [-s suffix] path...
FlagArgumentDescription
-ssuffixRemove trailing suffix from the result

Also supports --suffix=EXT long form.

PropertyTypeDescription
BashTextstringFilename with directory components stripped

Extract filename from path:

Terminal window
basename /home/beagle/work/script.ps1
script.ps1

Strip extension:

Terminal window
basename -s .ps1 /home/beagle/work/script.ps1
script

Process multiple paths:

Terminal window
basename /usr/bin/ls /usr/bin/cat
ls
cat

Combine with find:

Terminal window
find . -name '*.ps1' | ForEach-Object { basename $_.Path }

Strip last component from file name, returning the directory portion.

dirname path...
PropertyTypeDescription
BashTextstringDirectory portion of the path

Extract directory from path:

Terminal window
dirname /home/beagle/work/script.ps1
/home/beagle/work

Bare filename returns current directory marker:

Terminal window
dirname script.ps1
.

Root path:

Terminal window
dirname /usr
/

Combine with other commands:

Terminal window
$dir = dirname /home/beagle/work/script.ps1
ls -la $dir.BashText

The real power of these commands comes from combining them through the pipeline while keeping typed objects intact.

Filter ls output and access properties:

Terminal window
$large = ls -la | grep '.psm1' | sort -k5 -rn
$large[0].Name # "PsBash.psm1"
$large[0].SizeBytes # 141234
$large[0].Permissions # "-rw-r--r--"

Combine find with stat for detailed metadata:

Terminal window
find . -name '*.ps1' | ForEach-Object {
$s = stat $_.FullPath
[PSCustomObject]@{
Name = $_.Name
Size = $s.SizeBytes
Owner = $s.Owner
}
}

Disk usage analysis:

Terminal window
du -ah . | sort -k1 -rn | head 10

Directory tree filtered to directories:

Terminal window
tree -d -L 2 . | Where-Object { $_.IsDirectory }