Forrest logo
back to the [[ tool

shell:warp:b0b01

Check if a file exists and is a regular file
$ [[ -f ${file} ]]
try on your machine

This command is written in the Bash programming language.

The command checks whether a file exists or not, and if it exists, it is a regular file (not a directory, symbolic link, etc.).

Here is a breakdown of the command:

  • [[ -f ... ]]: This is a conditional expression in Bash, used to evaluate conditions. The -f flag is used to check if a file exists and is a regular file.
  • ${file}: This is a variable named "file" that holds the name or path of the file you want to check.

So, when this command is executed, it will check if the value stored in the "file" variable represents a regular file. If it is, the conditional expression will return true, and if it is not or the file doesn't exist, it will return false.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the [[ tool