Copying a bunch of buried files to another di

June 4, 2009 at 11:05:23
Specs: Ubuntu Linux 9.0
Hello,
Total beginner here, but a few weeks of trial and error. I'd like to make a script to backup of a bunch of buried movie files, within several levels of directories, copying them to a backup directory:

#!/bin/bash
# moves all claymation movies onto UNIX drive. Must be .mov format.

clay_DIR="/media/SG100GB/Documents\ and\ Settings/Geoff/My\ Documents/Art/Claymation"

dest_DIR=/Videos/AHK_Claymation

cd /
eval cd $clay_DIR
cp -prv *.mov $dest_DIR


exit 0

What am I doing wrong? the error is:
cp: cannot stat `*.mov': No such file or directory

so I know my pathing seems correct, and the problem lies in my use of the cp command.
Thanks!


See More: Copying a bunch of buried files to another di

Report •


#1
June 4, 2009 at 11:22:43
I wanted to clarify: the movies are buried within a few layers of directories, so the cp command needs to start at the clay_DIR path, and work its way thru each subdirectory, finding movies, copying them to the dest_DIR, then back up, then to the next one, down thru its directories, and so forth.
Perhaps what I want to do is too much for cp; Is there a better way to do this?

Thanks!


Report •

#2
June 4, 2009 at 11:51:56
I think your problem is that you are not changing to the clay_DIR directory before you perform the copy.

I have 3 observations in order of importance:

1) I pasted and cut this line onto my Solaris unix system:

clay_DIR="/media/SG100GB/Documents\ and\ Settings/Geoff/My\ Documents/Art/Claymation"

This and\ means line continuation, but I don't think the rest of the text is on the next line. Try removing \ and make sure all the text is on one line.

Also, what is the signifcance of the slashes around the and:

.....Documents\ and\ Settings....

I think your directory string setup is the biggest issue

2) I don't see a need to eval the cd command.

You might try checking the exit code after the cd to make sure it works:

clay_DIR="/media/......"
cd "$clay_DIR"
if [[ $? -ne 0 ]]
then
echo "change directory failed: "
exit
fi

3) Since you are using a full path:

/media .....

there is no need to:

cd /

If the other cd command is correct, your script should work.

Sorry, I didn't see your 2nd email. Yes, you probably are asking a lot of copy. Maybe you want to use the find command.


Report •

#3
June 4, 2009 at 15:10:56
Nails, Thank you!
The path problem was the root of the problem, the spaces didn't need an escape character (\), only the quotes for the string.
Then, the cd command also had to be quoted, which I didn't realize. Quoting preserves whitespace! so that fixed it up nice.

The find command is extreemely robust, and that's what I needed. The finished script is as follows, with important changes in bold.

#!/bin/bash
# copies all claymation movies onto UNIX drive. Must be .mov format. must be over 100 blocks

clay_DIR="/media/SG100GB/Documents and Settings/Geoff Clark/My Documents/Art/ArtHouseKids/Claymation"

dest_DIR="/home/gclark/Videos/AHK_Claymation"


cd "$clay_DIR" # you MUST quote these because the spaces in the path must be preserved.

if [[ $? -ne 0 ]]
then
echo "change directory failed: "
exit
fi


find . -name "*.mov" -size +100 -exec cp -v '{}' -t "$dest_DIR" \;

exit 0

Thanks!!


Report •

Related Solutions


Ask Question