hi all,
can i get script find file & copy that file with path
for an example
sourse : /home/abc/
destination : /home/backup/
files which need to find : tmp*
copy these files with its absolute path inside
like :- /home/abc/x/y/z/tmp.txt to /home/backup/date/x/y/z/tmp.txt
thanks for reply
hey can we do this using cp command.
i tried like this but it prints error
test=$(find /home/user/ -name test* -print0)
for i in $test; do cp -a $i /home/user/tmp/; done
Have you try to find out why it fails?
Put some effort into solving the problem with the given examples instead of always asking for the right answers.
cd /home/jagannath.n
dated=$(date +%d-%m-%y)
test -d /home/jagannath.n/tmp/$dated | mkdir /home/jagannath.n/tmp/$dated
file=$(find . -name test* -print)
cp -rf $file /home/jagannath.n/tmp/$dated
my problem is solved using above script but it print below error .
cp: cannot stat `./Azureus': No such file or directory
cp: cannot stat `Downloads/SHELL': No such file or directory
cp: cannot stat `SCRIPTING': No such file or directory
cp: cannot stat `IN': No such file or directory
cp: cannot stat `LINUX/VTC': No such file or directory
cp: cannot stat `-': No such file or directory
cp: cannot stat `UNIX': No such file or directory
cp: cannot stat `SHELL': No such file or directory
cp: cannot stat `SCRIPTING': No such file or directory
cp: cannot stat `ADVANCED/Course': No such file or directory
cp: cannot stat `Files/Chapter': No such file or directory
[quote the arguments properly]
(UNIX Shell Quotes - a simple tutorial). But just adding double quotes around "$file" doesn't really help, either, because it's not a single file. I'd still recommend using tar or cpio for this.
Note there are two |:s before the mkdir, it's an "or"; "a || b" is a shorthand for "if not a then b" (which is equivalent to "a or b").
#! /usr/bin/ksh
cd /home/backup/
find /home/abc/ -name "*.s" | while read line
do
p=$(dirname $line )
p1=$(echo $p | sed 's/\///')
mkdir -p $p1
cd $p1
tocopy=$(pwd)
echo $tocopy
cp $line $tocopy
cd -
done
#! /usr/bin/ksh
cd /home/backup/
find /home/abc/ -name "*.s" | while read line
do
p=$(dirname "$line" )
p1=$(echo $p | sed 's/\///')
mkdir -p $p1
cd $p1
tocopy=$(pwd)
echo $tocopy
cp "$line" $tocopy
cd -
done