[ -d directory ] Type the following command: Here is a sample shell script: General syntax to see if a directory exists or not
OR
test directory
See if a directory exists or not with NOT operator:
[ ! -d directory ]
OR
! test directoryFind out if /tmp directory exists or not
$ [ ! -d /tmp ] && echo 'Directory /tmp not found'
OR$ [ -d /tmp ] && echo 'Directory found' || echo 'Directory /tmp not found'
Sample Shell Script to gives message if directory exists
#!/bin/bash DIR="$1" if [ $# -ne 1 ] then echo "Usage: $0 {dir-name}" exit 1 fi if [ -d "$DIR" ] then echo "$DIR directory exists!" else echo "$DIR directory not found!" fi
Tuesday, November 18, 2008
How to check whether the directory is exist or not in Linux
Posted by PNA Prasanna at 2:35 AM
Labels: Linux Articles
Subscribe to:
Post Comments (Atom)
0 Comments:
Post a Comment