Sunday 30 October 2016

script to print file type in a directory

for filename in `ls -l`
do          
if [ -d $filename ]
    then
           echo $filename   it is a directory
                    elif [  -h $filename ]
                          then
                     echo $filename  it is a link
                     elif [ -f  $filename ]
                           then
                      echo $filename it is a file
fi
done

$ ./filetypecheck.ksh
filetypecheck.ksh it is a file
flashpoint it is a directory
new it is a file
new1 it is a file
newres it is a file
newrestu it is a file
newworld it is a file
test it is a directory

$ ls -l
total 12
-rwxr-xr-x 1 flash  363 Oct 29 23:31 filetypecheck.ksh*
drwxrwxr-x 2 flash4096 Oct 29 23:33 flashpoint/
-rw-rw-r-- 1 flash   0 Oct 29 23:22 new
-rw-rw-r-- 1 flash   0 Oct 29 23:22 new1
-rw-rw-r-- 1 flash   0 Oct 29 23:22 newres
-rw-rw-r-- 1 flash   0 Oct 29 23:22 newrestu
-rw-rw-r-- 1 flash   0 Oct 29  2016 newworld

drwxrwxr-x 2 flash 4096 Oct 29 23:22 test/

No comments:

Post a Comment