Skip to content

System Info

ps, env, date, hostname, whoami, which, balias, time, and sleep commands for process listing, environment inspection, and shell utilities.


Report a snapshot of the current processes. Returns structured PsEntry objects with typed properties for process ID, CPU, memory, and more.

ps [OPTIONS]
FlagDescription
auxBSD-style: show all processes with full columns
-e / -AShow all processes
-fFull-format listing (current user’s processes, no TTY restriction)
-u USERFilter by username
-p PIDFilter by process ID
--sort=KEYSort by key (prefix with - for descending)
-o COLSCustom column output (comma-separated)

Sort keys: pid, ppid, cpu, %cpu, mem, %mem, rss, vsz, user, comm, time

Custom columns (-o): pid, ppid, user, %cpu, cpu, %mem, mem, vsz, rss, tty, stat, start, time, command, cmd, comm, args

Each result is a PsBash.PsEntry object:

PropertyTypeDescription
PIDintProcess ID
PPIDintParent process ID
UserstringUsername of the process owner
CPUdoubleCPU usage percentage
MemorydoubleMemory usage percentage
MemoryMBdoubleResident memory in megabytes
VSZlongVirtual memory size in KB
RSSlongResident set size in KB
TTYstringControlling terminal
StatstringProcess state code
StartDateTimeProcess start time
TimestringCumulative CPU time (M:SS format)
CommandstringCommand line
CommandLinestringFull command line
ProcessNamestringShort process name
WorkingSetlongWorking set in bytes
BashTextstringFormatted text output line

List all processes (BSD-style):

Terminal window
ps aux
root 1 0.0 0.1 2456 1024 ? S 09:15 0:01 /sbin/init
you 1234 2.5 1.3 45600 13312 pts/0 Sl 10:30 1:42 pwsh

Top 5 processes by CPU usage:

Terminal window
ps aux | sort -k3 -rn | head 5

The output looks like text, but each result is still a PsEntry object. Properties survive the pipeline:

Terminal window
$top = ps aux | sort -k3 -rn | head 1
$top[0].PID # 1234
$top[0].MemoryMB # 13.0

Filter by user:

Terminal window
ps -u root

Filter by PID:

Terminal window
ps -p 1

Sort by memory descending:

Terminal window
ps aux --sort=-%mem

Custom column output:

Terminal window
ps -e -o pid,user,%cpu,%mem,command
1 root 0.0 0.1 /sbin/init
1234 you 2.5 1.3 pwsh

Access properties programmatically:

Terminal window
$procs = ps aux
$procs | Where-Object { $_.Memory -gt 1.0 } | ForEach-Object {
'{0}: {1} MB' -f $_.ProcessName, $_.MemoryMB
}

Print environment variables as structured objects. Both env and printenv call the same function.

env [VARNAME]
printenv [VARNAME]

When called with no arguments, lists all environment variables sorted by name. When called with a variable name, returns that single variable.

Each result is a PsBash.EnvEntry object:

PropertyTypeDescription
NamestringEnvironment variable name
ValuestringEnvironment variable value
BashTextstringFormatted as NAME=VALUE

List all environment variables:

Terminal window
env
HOME=/home/you
PATH=/usr/bin:/bin
SHELL=/bin/bash

Get a specific variable:

Terminal window
env HOME
HOME=/home/you

Access the value programmatically:

Terminal window
$home = env HOME
$home.Value # "/home/you"
$home.Name # "HOME"

Filter environment variables with grep:

Terminal window
env | grep PATH
PATH=/usr/bin:/bin
MANPATH=/usr/share/man

Count environment variables:

Terminal window
env | wc -l

Print the current date and time, or format a specific date. Returns a DateOutput object with typed date components.

date [OPTIONS] [+FORMAT]
FlagDescription
-d STRING / --date=STRINGDisplay time described by STRING instead of now
-u / --utc / --universalPrint in UTC
-r FILE / --reference=FILEDisplay the last modification time of FILE
+FORMATOutput format using % specifiers
SpecifierDescriptionExample
%YFour-digit year2026
%mMonth (01-12)04
%dDay of month (01-31)02
%HHour, 24-hour (00-23)14
%MMinute (00-59)30
%SSecond (00-59)45
%sSeconds since Unix epoch1775340645
%AFull weekday nameThursday
%BFull month nameApril
%ZTimezoneUTC
%aAbbreviated weekdayThu
%bAbbreviated monthApr
%eDay of month, space-padded 2
%jDay of year (001-366)092
%pAM/PMPM
%nNewline
%tTab
%%Literal %%

Each result is a PsBash.DateOutput object:

PropertyTypeDescription
YearintFour-digit year
MonthintMonth number (1-12)
DayintDay of month (1-31)
HourintHour (0-23)
MinuteintMinute (0-59)
SecondintSecond (0-59)
EpochlongUnix timestamp (seconds since 1970-01-01)
DayOfWeekstringFull weekday name
TimeZonestringTimezone identifier
DateTimeDateTimeOffsetThe underlying .NET DateTimeOffset
BashTextstringFormatted date string

Current date and time (default format):

Terminal window
date
Thu Apr 2 14:30:45 America/Chicago 2026

Custom format:

Terminal window
date '+%Y-%m-%d %H:%M:%S'
2026-04-02 14:30:45

Unix epoch timestamp:

Terminal window
date '+%s'
1775340645

Display a specific date:

Terminal window
date -d '2025-12-25'
Thu Dec 25 00:00:00 America/Chicago 2025

UTC output:

Terminal window
date -u
Thu Apr 2 19:30:45 UTC 2026

Last modification time of a file:

Terminal window
date -r package.json

Access properties programmatically:

Terminal window
$d = date
$d.Year # 2026
$d.Epoch # 1775340645
$d.DayOfWeek # "Thursday"

Print the system hostname.

hostname

PsBash.TextOutput with a single property:

PropertyTypeDescription
BashTextstringThe system hostname

Uses [System.Net.Dns]::GetHostName() for cross-platform compatibility.

Print the hostname:

Terminal window
hostname
my-workstation

Access the value programmatically:

Terminal window
$h = hostname
$h.BashText # "my-workstation"

Use in a formatted string:

Terminal window
$user = whoami
$host = hostname
printf '%s@%s\n' $user.BashText $host.BashText
you@my-workstation

Print the current username.

whoami

PsBash.TextOutput with a single property:

PropertyTypeDescription
BashTextstringThe current username

Uses [System.Environment]::UserName for cross-platform compatibility.

Print the current user:

Terminal window
whoami
you

Access the value programmatically:

Terminal window
$me = whoami
$me.BashText # "you"

Combine with other commands:

Terminal window
ps -u (whoami).BashText

Locate a command by name. Returns the path to the executable or function definition.

which [OPTIONS] NAME...
FlagDescription
-aShow all matches, not just the first

Each result is a PsBash.WhichOutput object:

PropertyTypeDescription
CommandstringThe command name that was looked up
PathstringResolved path or definition
TypestringCommand type (e.g., application, function, alias)
BashTextstringThe resolved path

Locate a command:

Terminal window
which pwsh
/usr/bin/pwsh

Show all matches:

Terminal window
which -a python
/usr/bin/python
/usr/local/bin/python

Check the command type:

Terminal window
$w = which grep
$w.Type # "alias"
$w.Path # "Invoke-BashGrep"
$w.Command # "grep"

Locate multiple commands:

Terminal window
which ls cat grep
Invoke-BashLs
Invoke-BashCat
Invoke-BashGrep

Define, display, or remove shell aliases. The command is named balias to avoid conflicting with PowerShell’s built-in alias command. The unalias command is also available.

balias [OPTIONS] [NAME[=VALUE]...]
unalias NAME...
unalias -a
FlagDescription
-pList all aliases (same as calling balias with no arguments)
-uUnalias mode (remove aliases)
-aRemove all aliases (used with -u)

Each result is a PsBash.AliasOutput object:

PropertyTypeDescription
NamestringAlias name
ValuestringAlias value (the command it expands to)
BashTextstringFormatted as alias name='value'

Define an alias:

Terminal window
balias ll='ls -la'

List all aliases:

Terminal window
balias
alias ll='ls -la'

Look up a specific alias:

Terminal window
balias ll
alias ll='ls -la'

Access properties programmatically:

Terminal window
balias mygrep='grep -rn'
$a = balias mygrep
$a.Name # "mygrep"
$a.Value # "grep -rn"

Remove an alias:

Terminal window
balias -u ll

Remove all aliases:

Terminal window
balias -u -a

Run a command and measure its execution time. Returns the command’s output along with timing information.

time COMMAND [ARGS...]

Each result is a PsBash.TimeOutput object:

PropertyTypeDescription
RealTimeTimeSpanWall-clock elapsed time
CommandstringThe command that was timed
ExitCodeintExit code of the command (0 = success)
BashTextstringThe command’s text output

The real time is also printed to stderr in the format real 0.123s.

Time a command:

Terminal window
time ls -la
-rw-r--r-- 1 you you 141234 Apr 2 10:30 PsBash.psm1
real 0.045s

Access timing properties:

Terminal window
$t = time sleep 2
$t.RealTime.TotalSeconds # ~2.0
$t.ExitCode # 0
$t.Command # "sleep"

Time a pipeline-producing command:

Terminal window
$t = time grep -r 'function' src/
$t.RealTime.TotalMilliseconds # elapsed ms

Delay execution for a specified amount of time. Produces no output.

sleep NUMBER[SUFFIX]...
SuffixMeaningExample
sSeconds (default)sleep 5s
mMinutessleep 2m
hHourssleep 1h
dDayssleep 1d

When no suffix is given, the number is treated as seconds. Multiple arguments are summed together.

Sleep for 3 seconds:

Terminal window
sleep 3

Sleep for 500 milliseconds:

Terminal window
sleep 0.5

Sleep with a suffix:

Terminal window
sleep 2m

Combine multiple durations:

Terminal window
sleep 1m 30s

This sleeps for 90 seconds total (1 minute + 30 seconds).