Shell script program to display property of file in linux/unix | Linuxteach

file property contains file name,file size and location of the file etc are mentioned.In this post i shared the shell script program to show the property of file.

file name is taken as input from user and its file property will be displayedin the output and it also show the owner of the filethe main command is used to display the file property is  ls -ld filename.

this command display the table consist of various column such as owner name,file size etc To display the file size we cut the column of the file size column from the output of the ls -ld file_name command and lastly we have displayed the file info using echo command.

Shell script program to display property of file in linux/unix


echo “ENTER FILE NAME”

read f1

name=`ls $f1`

echo “FILE NAME : $name”

owner=`ls -ld $f1 | cut -f3 -d ‘ ‘`

echo “FILE OWNER : $owner”

date=`ls -ld $f1 | awk ‘{print $6″ “$7}’`

echo “DATE MODIFIED : $date”

type=`file $f1`

echo “FILE TYPE : $type”

size=`ls -hld $f1 | cut -f5 -d’ ‘`

echo “FILE SIZE : $size”

output

Leave a comment