- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Move file but keep directory tree
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2005 07:39 AM
тАО09-27-2005 07:39 AM
I'd like to be able to keep the directory tree of the file when the file is in it's new location.
Example: I'd like to move the file stuff.gz from /home/jerry to /var/tmp/home/jerry.
Any suggestions on how to do this within the structure of my already written script?
(Main part of my script is below)
find / -name \*.gz >$OUTPUT
for i in $(<$OUTPUT)
do
{insert command here}
done
Thank you for any suggestions you may have.
Mike
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2005 07:45 AM
тАО09-27-2005 07:45 AM
Re: Move file but keep directory tree
find / -name \*.gz >$OUTPUT
for i in $(<$OUTPUT)
do
cp -rp $i /var/tmp/$i
rm $1
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2005 07:46 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2005 08:16 AM
тАО09-27-2005 08:16 AM
Re: Move file but keep directory tree
As the root user;
# cd /home/jerry
# find . -depth | cpio -pmuldv /var/tmp/
This will keep perms and owners as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2005 08:28 AM
тАО09-27-2005 08:28 AM
Re: Move file but keep directory tree
Alan - the cp command with the rp options did not create the directory structure on my HP-UX 11i box. The man page says p is for keeping permissions.
Clay & Rick - the cpio command works.
Here is how I incorporated it into my scripts...
find / -name \*.gz >$OUTPUT
cat $OUTPUT | cpio -dumpv /var/tmp
If anyone has a better way to incorporate it into my script I'd love to hear it.
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2005 08:59 AM
тАО09-27-2005 08:59 AM
Re: Move file but keep directory tree
Instead of the 2 lines you have, just have the single line as listed previously posted.
find /home/jerry -name '*.gz' | cpio -pmuldv /var/tmp
You can have just the 1 line doing the copies.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2005 09:43 AM
тАО09-27-2005 09:43 AM
Re: Move file but keep directory tree
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2005 05:10 PM
тАО09-27-2005 05:10 PM
Re: Move file but keep directory tree
for filename in `find / -name \*.gz`;
do
newdir=dirname $filename
mkdir -p /var/tmp/$newdir
mv $filename /var/tmp/$newdir
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2005 05:28 PM
тАО09-27-2005 05:28 PM
Re: Move file but keep directory tree
-Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2005 05:41 PM
тАО09-27-2005 05:41 PM
Re: Move file but keep directory tree
# find / -name "*.gz" | awk '{ print "cp -R "$0" /var/tmp" }' | ksh
It will copy directory sturcture to /var/tmp. You can change location also with awk statement.
hth.