The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
absolute path Kirichiko UNIX for Dummies Questions & Answers 2 10-03-2007 03:30 AM
$PWD shows absolute path vs path w/symbolic links kornshellmaven Shell Programming and Scripting 3 06-13-2007 09:15 AM
absolute path filedeliver High Level Programming 4 06-05-2007 02:18 PM
vi - replacing a relative path with absolute path in a file Yinzer955i UNIX for Dummies Questions & Answers 2 09-07-2006 08:47 AM
HOW to make absolute path???? HELP youngvet High Level Programming 1 11-01-2003 12:58 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-13-2008
Registered User
 

Join Date: Jan 2008
Posts: 52
Question find & copy files with absolute path

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 in advance
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-13-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
The customary tool for this would be tar.

Code:
cd /home/abc
test -d /home/backup/date || mkdir /home/backup/date
find -type f -name 'tmp*' -print |
tar cf - |
( cd /home/backup/date ; tar xf - )
You usually want to run this as root in order to preserve permissions etc.

rsync is also nice and efficient if you have that.
Reply With Quote
  #3 (permalink)  
Old 05-13-2008
Registered User
 

Join Date: Jan 2008
Posts: 52
find & copy files with absolute path

Quote:
Originally Posted by era View Post
The customary tool for this would be tar.

Code:
cd /home/abc
test -d /home/backup/date || mkdir /home/backup/date
find -type f -name 'tmp*' -print |
tar cf - |
( cd /home/backup/date ; tar xf - )
You usually want to run this as root in order to preserve permissions etc.

rsync is also nice and efficient if you have that.


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

whts wrong in my script

Last edited by jagnikam; 05-14-2008 at 09:15 AM.
Reply With Quote
  #4 (permalink)  
Old 05-14-2008
Registered User
 

Join Date: Jan 2008
Posts: 52
find & copy files with absolute path

Quote:
Originally Posted by jagnikam View Post
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

whts wrong in my script
please help me ASAP.
Reply With Quote
  #5 (permalink)  
Old 05-14-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
It is not clear that cp is the right tool for what you are trying to do.
Reply With Quote
  #6 (permalink)  
Old 05-14-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,988
You can try it with find and cpio, something like:

Code:
cd /home/abc
find tmp* -print | cpio -pvdmu /home/backup
Check the manpages for the used options.

Regards
Reply With Quote
  #7 (permalink)  
Old 05-14-2008
Registered User
 

Join Date: Jan 2008
Posts: 52
find & copy files with absolute path

Quote:
Originally Posted by Franklin52 View Post
You can try it with find and cpio, something like:

Code:
cd /home/abc
find tmp* -print | cpio -pvdmu /home/backup
Check the manpages for the used options.

Regards
thanks for reply
this script create folder named as "tmp" in tmp folder it does not find & copy files starts with "tmp*"


what i want script search the file "tmp" in abc & its subfolder & copy to destination
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
cpio, linux

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:32 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0