Windows
Linux
PowerShell Equivalents
File System
Windows PowerShell Test-Path equivalent in Linux
Tests whether a file, directory or other path exists for use in shell scripts.
Windows
→
PowerShell Test-Path
Linux equivalents
test -e path
test -e path
test -e path
Overview
What this command does
Tests whether a file, directory or other path exists for use in shell scripts.
Migration tip: The
test command returns an exit status rather than printing true or false. In Bash, [[ ... ]] is usually easier to read.Practical tasks
Common use cases
Check whether a path exists
Tests whether a file, directory or other path exists for use in shell scripts.
test -e file.txt && echo "exists"
Check for any path
[[ -f file.txt ]] && echo "regular file"
Check for a regular file
[[ -d folder ]] && echo "directory"
Check for a directory
Ready to run
Copyable Linux commands
Review paths, device names, package names and permissions before running any command.
test -e file.txt && echo "exists"
[[ -f file.txt ]] && echo "regular file"
[[ -d folder ]] && echo "directory"
Walkthrough
Examples with explanations
test -e file.txt && echo "exists" # check whether a path exists
[[ -f file.txt ]] && echo "regular file" # check for a regular file
[[ -d folder ]] && echo "directory" # check for a directory
Reference
Common options and variations
| Command or option | Use |
|---|---|
test -e file.txt && echo "exists" | Check for any path |
[[ -f file.txt ]] && echo "regular file" | Check for a regular file |
[[ -d folder ]] && echo "directory" | Check for a directory |
Distro differences
Debian/Ubuntu vs Fedora vs Arch
This command is the same on Debian/Ubuntu, Fedora and Arch Linux when the relevant tool is installed.
| Distribution | Package manager / base | Equivalent command | Difference to notice |
|---|---|---|---|
| Debian/Ubuntu | same command | test -e path |
Same command on this distribution. |
| Fedora | same command | test -e path |
Same command on this distribution. |
| Arch | same command | test -e path |
Same command on this distribution. |
Keep learning