Saturday, March 27, 2010

파일이 존재하는지 체크

Find out if file /etc/passwd file exists or not
Type the following commands:
$ [ -f /etc/passwd ] && echo "File exists" || echo "File does not exists"
$ [ -f /tmp/fileonetwo ] && echo "File exists" || echo "File does not exists"
Find out if directory /var/logs exists or not
Type the following commands:
$ [ -d /var/logs ] && echo "Directory exists" || echo "Directory does not exists"
$ [ -d /dumper/fack ] && echo "Directory exists" || echo "Directory does not exists"
다음과 같이 짤수 있음.
#!/bin/bash
FILE=$1

if [ -f $FILE ];
then
echo "File $FILE exists"
else
echo "File $FILE does not exists"
fi
키워드 : check, shell

레퍼런스 : Linux/UNIX: Find Out If File Exists With Conditional Expressions

No comments:

Post a Comment