This is good to test a file has enough permission to do read, write or execute operations. For a good programmer, you should use these functions before doing any operations on the file. 1. Test read permission: Below script will check if the given file has read permission for currently logged in user. This will be useful to test before start reading any file inside a shell script.
1 2 3 4 5 6 7 8 | #!/bin/bash if [ -r /tmp/myfile.txt ] then echo "File has read permission" else echo "You don't have read permission" fi |
2. Test write permission: Below script will check if a given file has to write permission for currently logged in user. This will be useful to test before writing content to…