postheadericon Write a script to display the name of those files (in the given directory) which are having multiple links.

 

clear
echo "Enter Directory : "
read dir

# check inputed name is directory or not
if [ ! -d $dir ]
then
echo "DIRECTORY [ $dir1 ] NOT EXIST"
exit 1
fi

#count total number of lines
len=`ls -l $dir | wc -l`
i=2

echo "File With Multiple Link are "

while [ $i -le $len ]
do
# select one by one record from entire group of records
record=`ls -l $dir | head -n $i | tail -n 1`

#grab the file name
f=`echo $record | cut -d " " -f 8`

#grab the total hard link to that file
link=`echo $record | cut -d " " -f 2`

#if multiple links then print file with link
if [ $link -gt 1 ]
then
echo "$f = $link"
fi

#increment the counter
i=`expr $i + 1`
done

1 comments:

Follow by Email

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.