Skip to content

24 ways to check the status of files using if commands on Linux

There are a lot more ways to check files using if commands than many of us realize. Although this information is included in the bash man page, that man page has thousands of lines and you could easily find yourself paging down more than 100 times to reach it.

This post, provides information on each option and examples for some of the most useful ones.

[ Get regularly scheduled insights by signing up for Network World newsletters. ]

Checking if a file exists

One of the most commonly used tests for checking on files is if [ -f filename ]. This test will result in true if the file exists and is a regular file—not a directory or a symbolic link. You might use it like this:

To read this article in full, please click here

Source:: Network World – Data Center