From the course: Linux System Engineer: Bash Shell Scripting for Automation

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

File conditions

File conditions

From the course: Linux System Engineer: Bash Shell Scripting for Automation

Start my 1-month free trial

File conditions

- [Instructor] Using if conditionals, we can do quite a few tests on files. Let's get right into it. Dash e checks if the file exists. Now in Linux, everything is a file, including devices. This check doesn't discern. Dash f, however, checks if a file exists and is a file. Dash d checks if a file exists and is a directory. Dash c checks if a file exists and is a character device. Dash b checks if a file exists and is a block device. Dash p checks if a file exists and is a named pipe. Dash capital S checks if a file exists and is a socket. Dash capital L checks if a file exists and is a symbolic link. Dash g checks if a file exists and has the SGID bit set. Dash u checks if a file exists and has the SUID bit set. Dash r checks if a file exists and is readable by the current user. Dash w checks if a file exists and is writable by the current user. Dash x checks if a file exists and is executable by the current user. Dash s checks if a file exists and it has a size larger than zero…

Contents