-1

I have the follwoing problem: I want to make a script that backups a certain directory completely to another directory. I may not use cp -r or any other recursive command. So I was thinking of using a while or for loop. The directory that needs to be back upped is given with a parameter. This is what I have so far:

OIFS="$IFS"
IFS=$'\n'

for file in `find $1`
do
  cp $file $HOME/TestDirectory
done

IFS="$OIFS"

But when I execute it, this is what my terminal says: Script started, file is typescript

Mavix
  • 181
  • 1
  • 3
  • 13

1 Answers1

1

Try this:

find "$1" -type f -print0 | xargs -0 cp -t $HOME/TestDirectory

Don't run your script through script !

Add this (shebang) at top of file:

#!/bin/bash

find "$1" -type f -print0 | xargs -0 cp -t $HOME/TestDirectory

change permission of your script for adding executable flag:

chmod +x myScript

run your script localy whith arguments:

./myScript rootDirectoryWhereSearchForFiles
F. Hauri - Give Up GitHub
  • 64,122
  • 17
  • 116
  • 137
  • Thanks! And I now know why my terminal said "file is script". That was because I named the script "script". – Mavix Dec 19 '12 at 19:18