Testing file types

While testing for values, we can test for the existence of a file or file type. For example, we may only want to delete a file if it is a symbolic link. We use this while compiling a kernel. The /usr/src/linux directory should be a symbolic link to the latest kernel source code. If we download a newer version before compiling the new kernel, we need to delete the existing link and create a new link. Just in case someone has created the /usr/src/linux directory, we can test if it has a link before removing it:

# [ -h /usr/src/linux ] &&rm /usr/src/linux  

The -h option tests that the file has a link. Other options include the following:

More options do exist, so delve into the main pages as you need to. We will use different options throughout the book, and thus giving you practical and useful examples.