Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

how to check a path is file or director in shell script

#!/bin/bash

########### to check for a directory ###########
path="./folder"
if [[ -d $path ]]; then
	echo "$1 Directory exists"
fi

# or

[ -d "folder" ] && echo Directory exists

########### to check for a file ###########
path="./file.txt"
if [[ -f $path ]]; then
	echo "$1 File exists"
fi

# or

[ -f "file.txt" ] && echo file exists
 
PREVIOUS NEXT
Tagged: #check #path #file #director #shell #script
ADD COMMENT
Topic
Name
9+2 =