본문 바로가기

Linux

Bash file check

Bash file check

To test file existence, the parameter can be any one of the following:

-e: Returns true value, if file exists
-f: Return true value, if file exists and regular file
-r: Return true value, if file exists and is readable
-w: Return true value, if file exists and is writable
-x: Return true value, if file exists and is executable
-d: Return true value, if exists and is a directory

Example script,

#!/bin/bash
FILE=$1

if [ -f "$FILE" ];
then
   echo "File $FILE exists"
else
   echo "File $FILE does not exist"
fi


'Linux' 카테고리의 다른 글

Git Pull All Repository  (0) 2017.01.19
Bash scrtipting  (0) 2017.01.10
Linux network interface configuration  (0) 2016.12.27
Ubuntu Paper Theme  (0) 2016.11.21
Ubuntu chrome keyring  (0) 2016.10.30