Run a command at a specific time
Schedule a one-shot command to run at a given clock time — `at` on Unix, Task Scheduler on Windows.
How to run a command at a specific time in each shell
Bashunix
echo "/path/to/script.sh" | at 14:30Zshunix
echo "/path/to/script.sh" | at 14:30Fishunix
echo "/path/to/script.sh" | at 14:30PowerShellwindows
Register-ScheduledTask -TaskName OneShot -Trigger (New-ScheduledTaskTrigger -Once -At "14:30") -Action (New-ScheduledTaskAction -Execute pwsh.exe -Argument "-File C:\path\to\script.ps1")cmd.exewindows
schtasks /create /sc once /st 14:30 /tn "OneShot" /tr "C:\path\to\script.bat"Equivalents listed for Bash, Zsh, Fish, PowerShell, cmd.exe.
Gotchas & notes
- `at` is OPT-IN on modern Linux — install via `apt install at` / `dnf install at` + `systemctl enable --now atd`. macOS ships `at` but `atrun` is disabled by default — `sudo launchctl load -F /System/Library/LaunchDaemons/com.apple.atrun.plist` to enable. Without `atd` / `atrun` running, `at` queues the job but it never fires.
- Time syntax `at` accepts: `HH:MM` (24h, today; tomorrow if past), `noon`, `midnight`, `teatime` (=4pm — yes, really), `now + 1 hour`, `5pm tomorrow`, `Jul 31`, `2026-07-31 14:30`. List queued jobs with `atq`; cancel with `atrm JOBID`. Inspect a job's command: `at -c JOBID` (also shows the full environment captured at submit time).
- Windows `schtasks /sc once /st HH:MM` schedules at a specific clock time TODAY (assumed; will fire tomorrow if HH:MM has passed). For a future date: add `/sd MM/DD/YYYY` (locale-dependent format — match the system locale or `schtasks` errors). `/ru USER /rp PASSWORD` runs as a specific user (UAC-elevated tasks need this).
- For "5 seconds from now" without a scheduling daemon: `(sleep 5; command) &` (bash — backgrounds the sleep+cmd subshell, foreground returns immediately; the parent shell must stay alive). pwsh: `Start-Job -ScriptBlock { Start-Sleep 5; command }` (background job, survives parent shell if you `Disconnect-Job`). For longer waits (minutes/hours) where the shell may exit, you NEED `at` / `schtasks` / `Register-ScheduledTask` — the daemon outlives the shell.
Related commands
Related tasks
- Schedule a cron job— Configure a recurring scheduled task — cron on Linux, launchd on macOS, Task Scheduler on Windows.
- Run a command every N seconds— Repeat a command on a fixed-interval polling loop — useful for live dashboards, healthcheck-watching, and tail-style log monitoring.
- Time how long a command takes— Measure the wall-clock (and optionally CPU / RSS) time of a single command run, for ad-hoc perf checks or regression testing.
- Run a command in the background— Launch a long-running command without blocking the current shell session.