bash script check file and directory

How to check file and directory in directory, I use bash script if file exists.
To write simple bash script check folder /home/huupv/Desktop all file and directory.
  1. The first, use for loop /home/huupv/Desktop/*
  2. The secondary, to check if a directory then echo, elif a file then echo.
My bash scripts check file and directory
    #!/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
bash script check file and directory

The running bash script check file and directory
$ ./studyscript.sh 
The 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

Comments

Popular posts from this blog

zimbra some services are not running [Solve problem]

Bash script list all IP addresses connected to Server

How to install php7 on centos 6