The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
combining mv and compress command sam_78_nyc Shell Programming and Scripting 4 11-06-2007 11:45 AM
Compress command indira UNIX for Dummies Questions & Answers 5 08-20-2007 11:04 AM
Copy and compress here2learn UNIX for Dummies Questions & Answers 4 11-30-2005 05:29 AM
Compress and copy a Folder scorpiyanz UNIX for Advanced & Expert Users 1 08-19-2005 10:53 AM
Help on compress command rahulrathod SCO 1 09-28-2004 01:11 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-13-2007
Registered User
 

Join Date: Sep 2007
Posts: 18
Copy Compress as one command

Hi,
I need to copy and compress files in a directory in single line of command. I am able to copy and gzip files in one command but not directory. Command that I am using for copying directory is below :

cp -rp /u01/app/<directory> /u01/app/backup |gzip -r
/u01/app/backup/<directory>

Thanks,
Prakash
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-13-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
something like

Code:
find /source -type f | while read N
do
      mkdir -p /target/`dirname $N`
      compress <$N >/target/$N
done
Reply With Quote
  #3 (permalink)  
Old 10-15-2007
Registered User
 

Join Date: Sep 2007
Posts: 18
Thanks porter. This is exactly was I was looking for.
Reply With Quote
  #4 (permalink)  
Old 11-23-2007
Registered User
 

Join Date: Sep 2007
Posts: 18
I used below code as suggested by Porter for compressing and copying directory.

find ${COPY_DIR} -type f | while read N
do
mkdir -p "${BACKUP_DIR}/`dirname $N`"
gzip < $N > ${BACKUP_DIR}/$N.gz
done

However I have some directories which have space in name. I get below error when copying and compressing directories which have sapce in name.

/backup/sidora/iAS/ifs1.1/doc/Quick Tour/Graphics/rtarr.gif.gz: cannot create

Any ideas on how can I take fix above error. Thanks in advance.
Reply With Quote
  #5 (permalink)  
Old 11-23-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,448
replace this to

Code:
gzip < $N > ${BACKUP_DIR}/$N.gz
Code:
gzip < "$N" > "${BACKUP_DIR}/$N.gz"
Reply With Quote
  #6 (permalink)  
Old 11-24-2007
Registered User
 

Join Date: Sep 2007
Posts: 18
Thanks for update matrixmadhan. Even though after making suggsted changes I still get same error message. Now my code looks like :

find ${COPY_DIR} -type f | while read N
do
mkdir -p "${BACKUP_DIR}/`dirname $N`"
gzip < "$N" > "${BACKUP_DIR}/$N.gz"
done

Error message

/backup/sidora/iAS/ifs1.1/doc/Quick Tour/Graphics/rtarr.gif.gz: cannot create
Reply With Quote
  #7 (permalink)  
Old 11-24-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,448
Just to make sure, do you have enough permissions to create the file in the specified directory ?
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:39 PM.


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

Content Relevant URLs by vBSEO 3.2.0