bash : add info how to check that file exists.

This commit is contained in:
Dmitry Voronin 2023-12-09 20:05:40 +03:00
parent 771999f055
commit 72d0b6cbe2
2 changed files with 33 additions and 0 deletions

9
.editorconfig Normal file
View file

@ -0,0 +1,9 @@
root = true
[*]
end_of_line = lf
charset = utf-8
indent_style = tab
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

View file

@ -0,0 +1,24 @@
# Check if file exists in Bash.
* -f file: True if the file exists and is a regular file.
* -d file: True if the file exists and is a directory.
* -s file: True if the file exists and has a size greater than zero.
* -r file: True if the file exists and is readable.
* -w file: True if the file exists and is writable.
* -x file: True if the file exists and is executable.
* -L file: True if the file exists and is a symbolic link.
* -e file: True if the file exists (regardless of type).
Here are examples using -e, -f, -d options to check if file or directory exists:
> Using -e option to check if a file or directory exists. It returns true if the specified path exists, regardless of whether it is a regular file, a directory, a symbolic link, or any other type of file.
```bash
#!/bin/bash
if [ -e /path/to/your/file ]; then
echo "File or directory exists."
else
echo "File or directory does not exist."
fi
```