Sunday, February 14, 2016

Script for finding a file and copy to a Specific directory

#!/bin/bash
# Script for finding a file and copy to a Specific directory
read -p "write the name of file: " a

file=`find / -name $a`
if [ $? -eq 0 ]
then
 {
  echo "*********************"
  echo "* $a File found which u r looking for     *"
  echo "*********************"
  read -p " where do u want to copy it: " b
  cp $file $b
}
else
 echo "file not found"
fi

###########################################
IF we find  More than one  files then we can use this script
###########################################
#!/bin/bash
 read -p "write down the file name : " file
find / -name $file>/shell/find
grep $file /shell/find
if [ $? -eq 0 ]
   then
  {
    valfile=`cat /shell/find`
    line=`sed -n 2p /shell/find`
    if [ ! -z "$line" ]
      then
      {
       echo ""
       read -p "Hey !!! select to copy from above" c
       echo ""
       read -p "Place where to copy :" d
       cp $c $d
       echo ""
       echo "File Copied to $d"
       echo ""
      }
    else
      {
       echo ""
       read -p "Place where to copy :" f
       cp $valfile $f
       echo ""
       echo "File Copied to $f"
       echo ""
      }
    fi
  }
  else
    echo ""
    echo "File not exixt"
    echo ""
  fi

4 comments: