Skip to content
shellmap

touchCreate an empty file or update its modification time if it exists across all 5 shells

Equivalents in every shell

Bashunix
touch file.txt

External `/usr/bin/touch`. Creates the file if missing (with the current time); updates atime + mtime if it exists. `-a` updates only atime, `-m` only mtime.

Zshunix
touch file.txt

Same external binary; identical behaviour to bash.

Fishunix
touch file.txt

External binary. Behaves identically across all Unix shells.

PowerShellwindows
New-Item file.txt

Creates an empty file but ERRORS if the file already exists. To update mtime on an existing file, set the property: `(Get-Item file.txt).LastWriteTime = Get-Date`. There is no single cmdlet that does both.

cmd.exewindows
type nul > file.txt

Idiomatic cmd workaround. `type nul` produces no output; redirected to a file, it creates an empty one. Does NOT preserve content — if the file already exists, it is TRUNCATED to zero bytes.

Worked examples

Create a new empty file

Bash
touch newfile.txt
Fish
touch newfile.txt
PowerShell
New-Item -ItemType File newfile.txt
cmd.exe
type nul > newfile.txt

Update mtime of an existing file to right now

Bash
touch existing.txt
PowerShell
(Get-Item existing.txt).LastWriteTime = Get-Date
cmd.exe
copy /b existing.txt +,, >nul

Create a file with a specific timestamp

Bash
touch -t 202601011200 file.txt
PowerShell
(Get-Item file.txt).LastWriteTime = [datetime]"2026-01-01 12:00"

Gotchas

  • PowerShell `New-Item file.txt` errors if the file exists. Wrap with `if (-not (Test-Path file.txt)) { New-Item file.txt }`, or pass `-Force` to overwrite (DESTROYING content). There is no equivalent of `touch`'s idempotent create-or-update.
  • Cmd `type nul > file.txt` TRUNCATES the file if it already exists — content is lost. Use `copy /b file.txt +,, >nul` to update mtime in place; the no-op concatenation is the canonical Windows mtime-touch trick.
  • Bash `touch -a` updates only access time, but most modern filesystems mount with `relatime` or `noatime` and may IGNORE atime updates entirely. Don't rely on `touch -a` for marker files in production.
  • Creating thousands of files with `touch a b c ... z` is fast on Unix but slow on Windows via `New-Item` — each call spawns a full pipeline. Expect 10–50× overhead for large fan-outs and prefer a single `[System.IO.File]::Create` loop.
  • Touching a SYMLINK with bash `touch` updates the TARGET's mtime, not the link's. Pass `-h` if you want to operate on the symlink metadata itself rather than the file it points to.

WSL & PowerShell Core notes

pwshOn Linux/macOS pwsh the system `/usr/bin/touch` resolves first (no alias collision), so `touch file.txt` works exactly like bash. On Windows pwsh, `touch` is NOT a built-in — you must use `New-Item` / `Get-Item` or install a third-party `touch.exe` (Git for Windows ships one).
WSLWSL `touch /mnt/c/path/file` works but goes through DrvFs, so creating many files in a Windows directory is significantly slower than on the native Linux filesystem. Stage files in `~/` first and `mv` to the Windows mount in one operation for best throughput.

Common tasks using touch

Related commands