2

I have text files in certain sub folders like home/andhra1/node1/*.txt files and home/andhra1/noden/*.txt and home/andhra2/node1/*.txt. I have to all files from different sub directories to one directory.

below is the shell script which i wrote

fromPath='source path'
echo $fromPath
file='destination path/*.pdf'
echo $file
toPath='destination path'
echo $toPath
for i in $file;
do
  filePath=$i
  if [ -e $filePath ];
  then
    echo $filePath
    yes | cp -rf $filePath $toPath
  else
    echo 'no files'
  fi
done
  • 2
    mv ~/node*/*.txt destinationPath/ ? – JJoao Sep 21 '16 at 11:32
1

Try with this code:

find /home/andhra1 -maxdepth 3 -name "*.txt" -type f -exec mv '{}' 
destinationPath/ \;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.