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
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
Labels:
shell script,
unix
Subscribe to:
Post Comments (Atom)
Subjects
- WordPress
- Mobile Computing-4649303 Practical Solution
- Android Programming New Syllabus Theory
- PHP LAMP Question Bank
- PHP LAMP Theory
- Step by Step Android Example
- Android Practical
- Android Theory
- Android Question Bank
- Networking FON Practical
- Networking FON Theory
- OS Practical
- OS Theory
- HTML
- JavaScript
- J2EE WTAD Theory
- J2EE WTAD Question Bank
- J2EE WTAD Quick Guide
- J2EE WTAD GTU Papers
- J2EE WTAD Practical
- Python
- JAVA Theory
- JAVA Practical
- MIS
Categories
- Android (55)
- c (11)
- Configure Tomcat7 (2)
- CSS (3)
- Decryption (16)
- Difference (1)
- Encryption (16)
- Error Detection and Correction Techniques (3)
- FON (27)
- Framing Technic (2)
- install Tomcat (2)
- J2EE (29)
- JAVA (13)
- JavaScript (19)
- linux (8)
- OS (17)
- PHP (11)
- Protocol (3)
- SERVER SOCKET PROGRAMING (7)
- Servlet (13)
- shell script (33)
- unix (22)
- WTAD (34)
Total Pageviews
© BipinRupadiya.com. Powered by Blogger.
1 comments:
this code can be done in this way also...
clear
i=2
ls -l > 1.txt
l=`ls -l | wc -l`
#ln -L oldfile newfile
echo "========================"
echo "Multiple links file name"
echo "========================"
while [ $i -le $l ]
do
a=`ls -l | head -$i | tail -1 | cut -c 12`
b=`ls -l | head -$i | tail -1 | cut -c 55-61`
if [ $a -ge 2 ]
then
echo "File name is :$b"
fi
i=`expr $i + 1`
done
echo "========================"
Post a Comment