x

File operations in Unix

Prev     Next

File operations in Unix : -s in Unix – To check whether file exists in the specified folder and it is not an empty file.


Ex:

Execution results:

-f in Unix – To check whether exists from the given path. This will just check whether file exists or not irrespective of whether file has content or not. It will check for the files not the directories. See below the details.

Ex:

-d in unix:- To check whether the directory is available or not. This kind of operations are widely useful in real time scenarios. This will check whether the given directory exists or not.

Ex:


-x in Unix:- To check whether the file has the executable permission or not. If the file has the permission to execute (either 744, 755, 777 etc) then it will return true else it will return false.

Ex:

-w in Unix:- To check whether the file is having the write permission or not. If the file has write access then it will return true else it will return false. The below file does not have write access, so it returns false.

Ex:

-r in Unix:- To check whether the file is having the Read permission or not. If the file has Read access then it will return true else it will return false. The below file does not have read access, so it returns false.

Ex:

Prev     Next



Like it? Please Spread the word!