new-item — PowerShell's create-file/directory cmdlet — like touch + mkdir across all 5 shells
Equivalents in every shell
touch file.txtTouch creates an empty file (or updates the mtime of an existing one). For directories use `mkdir dir/`; `mkdir -p a/b/c` creates intermediate dirs. Bash has NO unified file/dir constructor — they're separate binaries with different flags and different idempotency rules.
touch file.txtSame external binaries. macOS `touch` and `mkdir` are BSD-derived; `mkdir -p` and `touch` behave identically to GNU coreutils for everyday use. The `-r refFile` and `-d date` flags differ slightly between BSD touch and GNU touch.
touch file.txtSame externals. Fish has no built-in file-creation primitive. Common idiom for ensuring a writable file path exists: `mkdir -p (dirname $path); and touch $path` — fish's `and` separator chains commands like `&&`.
New-Item -ItemType File file.txtPowerShell-native cmdlet (alias `ni`). `-ItemType` is the type discriminator: `File`, `Directory`, `SymbolicLink`, `HardLink`, `Junction`. `-Force` recreates intermediate parent directories (the `mkdir -p` analogue) AND overwrites an existing file — same flag, two different effects per `-ItemType`. PowerShell also exposes a `mkdir` FUNCTION that wraps `New-Item -ItemType Directory -Force`.
type nul > file.txtNo single `touch`-equivalent — `type nul > file.txt` writes 0 bytes to create an empty file (overwrites if exists); `copy /b nul file.txt` is similar. For directories `md` / `mkdir` work; `mkdir a\b\c` creates intermediates automatically — no `-p` needed.
Worked examples
Create an empty file
touch newfile.txtNew-Item -ItemType File newfile.txttype nul > newfile.txtCreate a directory (and intermediates if missing)
mkdir -p a/b/cNew-Item -ItemType Directory -Force a/b/cmkdir a\b\cCreate a symlink pointing to another path
ln -s /target/path linknameNew-Item -ItemType SymbolicLink -Path linkname -Target /target/pathmklink linkname \target\pathGotchas
- `New-Item -Force file.txt` OVERWRITES an existing file with an empty one — this is NOT what `touch -a file` does (touch just bumps the timestamp). To match touch's idempotent-create semantics: `if (-not (Test-Path file.txt)) { New-Item file.txt }`. For mtime-bumping use `(Get-Item file.txt).LastWriteTime = Get-Date`.
- `-Force` is the `mkdir -p` analogue for directories (creates parents), but it's ALSO the overwrite flag for files — same flag, different effect per `-ItemType`. Read the `-ItemType` value before adding `-Force`; it's easy to nuke an existing file thinking you're being defensively idempotent.
- Symlinks require ELEVATED Windows sessions OR Developer Mode enabled (`Settings → Privacy & security → For Developers → Developer Mode`). Without it, `New-Item -ItemType SymbolicLink` fails with `Administrator privilege required`. The same applies to cmd `mklink`. Linux / macOS `ln -s` has no such requirement.
- The PowerShell `mkdir` function passes its argument to `New-Item -ItemType Directory -Force`, so `mkdir foo` silently SUCCEEDS if `foo` already exists — different from Unix `mkdir foo` which errors `File exists`. For strict-error behaviour use `New-Item -ItemType Directory foo` (no `-Force`).
- `New-Item -Path file.txt -Value 'content'` initialises the file with content (create + write in one call). The default ENCODING is `Default` on PS 5.1 (system code page) and UTF-8 NO BOM on PS 7+ — different bytes on disk for non-ASCII. Specify `-Encoding UTF8` explicitly for cross-version reproducibility.