$ [ -f /etc/passwd ] && echo "File exists" || echo "File does not exists"
$ [ -f /tmp/fileonetwo ] && echo "File exists" || echo "File does not exists"
$ [ -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
$chmod x script.sh
$./script.sh /path/to/file
$./script.sh /etc/resolv.conf
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)