Monday 9 April 2018

Shell script to display file attributes

#Script to extract and display the file attributes
echo "Enter the file name"
read f1
if [ -e $f1 ]
then
ap=`ls -l $f1 | cut -c2-10`
fn=`ls -l $f1 | tr -s " " | cut -d " " -f9`
lmt=`ls -l $f1 | tr -s " " | cut -d " " -f6,7,8`
sof=`ls -l $f1 | tr -s " " | cut -d " " -f5`
nol=`ls -l $f1 | tr -s " " | cut -d " " -f2`
un=`ls -l $f1 | tr -s " " | cut -d " " -f3`
fi
echo "The access permission of the given file is: $ap"
echo "The filename of the given file is: $fn"
echo "The last modification time of the given file is: $lmt"
echo "The size of given file is: $sof"
echo "The number of links of the given file: $nol"
echo "The username of the given file is: $un"



Safi>sh fchar.sh
Enter the file name
fchar.sh
The access permission of the given file is: rw-r--r--
The filename of the given file is: fchar.sh
The last modification time of the given file is: Apr 9 21:43
The size of given file is: 588
The number of links of the given file: 1
The username of the given file is: csc

No comments:

Post a Comment