The following are various options for binary file operations using test, which is taken from the Bash reference manual available at http://www.gnu.org/software/bash/:
Test Operator |
Tests True If |
[ file_1 -nt file_2 ] |
Check whether file_1 is newer than file_2 |
[ file_1 -ot file_2 ] |
Check whether file_1 is older than file_2 |
[ file_1 -ef file_2 ] |
Check whether file_1 and file_2 have the same device or inode numbers |
Let's write the script test07.sh to test the basic file attributes, such as whether it is a file or folder and whether it has a file size bigger than 0. The output will be different depending on whether the case file is present:
#!/bin/bash # Check whether file is Directory ...