To write simple bash script check folder /home/huupv/Desktop all file and directory.
- The first, use for loop /home/huupv/Desktop/*
- The secondary, to check if a directory then echo, elif a file then echo.
#!/bin/bash
# Author: HuuPV
for file in /home/huupv/Desktop/*
do
if [ -d "$file" ]
then
echo "$file is directory"
elif [ -f "$file" ]
then
echo "$file is file"
fi
done
The running bash script check file and directory
$ ./studyscript.shThe output as bellow
/home/huupv/Desktop/Barbarpower Template.xml is file
/home/huupv/Desktop/HuuPV is directory
/home/huupv/Desktop/like_fb.sh is file
/home/huupv/Desktop/post-fb.docx is file
/home/huupv/Desktop/Untitled Document 1 is file
Thanks for reading bash script check file and directory My blog Zimbra Mail Server,linux,bash script,centos,linux command I hope this is useful.