Code In Tech - The Ultimate World of Computer Technology

Monday 4 June 2012

Write a shell script. to remove files having following properties…(i) Remove all files having exactly 3 characters. (ii) Remove all files having specified extension. (iii) Remove all files having Name starting with lower case letters and ending with digits.

SOURCE CODE:
echo “1: File having only 3 char."
echo “2: File having specified extension.”
echo “3: File having name starting with lower case letters and ends at digits.”

echo “Enter your choice:”
read c
if [ $c = 1 ]
then
     echo “Files are…”
     ls ???

     echo “Do you want to delete these files?y/n”
     read s
     if [ $s = ‘y’ ]
     then
           for file in `ls ??? `
           do
                rm $file
           done
     else
           break
     fi
fi
if [ $c = 3 ]
then
     echo “Files are…”
     ls [ a-z ] * [0-9]
     echo “Do you want to delete these files?y/n”
     read s
     if [ $s = ‘y’ ]
     then
           for file in `ls [ a-z ] * [0-9] `
           do
                rm $file
           done
     else
           break
     fi
fi

if [ $c = 2 ]
then
     echo “Enter the special extension of file”
     read e
     echo “Files are…”
     ls *.$e
     echo “Do you want to delete these files?y/n”
     read s
     if [ $s = ‘y’ ]
     then
           for file in `ls * $e`
           do
                rm $file
           done
     else
           break
     fi
fi

OUTPUT:

1: File having only 3 char.
2: File having specified extension.
3: File having name starting with lower case letters and ends at digits.

Enter your choice:
3
Files are...
Desktop
Documents
Downloads
Music
Pictures
Public
Videos

Do you want to delete these files?y/n
n
      

No comments :

Post a Comment