File Test
noun
say it: “FYL TEST” /ˈfaɪl ˈtɛst/
A check a script makes about a file, such as whether it exists, is a folder, or has changed since a copy was made.
What is a file test in bash?
A file test asks a question about a path inside [[ ]]: -e is it there, -f is it a file, -d is it a folder, -s does it have anything in it, and a -nt b was a changed after b. ! turns the answer around, so a script can check before it acts.
if [[ ! -e "$file" ]]; then
echo "There's no $file here."
fi
In a sentence
- “The script's first file test stops it when the file name was mistyped.”
- “A file test with -nt lets the backup copy only what changed.”
Level: Apprentice · More Unix terms at this level
Updated