Skip to content
Advertisement

Why does the file in a subdirectory not get copied?

I have to make a script which will copy all files from a certain location starting with “db.” to another location. My script works fine for all files which are directly in the directory, but it doesnt copy any files which are in subdirectorys. I have used the parameter -r, which should copy everything recursivly or not? Why isnt it working and how can I make it work?

My script:

#! /bin/bash

#Script zum kopieren aller Dateien welche mit "db." beginnen.

#User input
echo -n 'Enter path to copy from: '
read copypath

echo -n 'Enter path to save to: '
read savepath

cp -r $copypath/db.* $savepath

echo 'Done.

Advertisement

Answer

Making an answer out of my comment…

try $copypath/db.* followed by $copypath/**/db.*

The first one is for the top level directory (copypath) and the next for any of the subdirectories.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement