Compress the contents of a directory while copying data into it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compress the contents of a directory while copying data into it
# 1  
Old 01-12-2009
Compress the contents of a directory while copying data into it

Hi guys

I have a need to compress the contents of a directory while I am copying data into it. I was able to do this when it was only one file by doing as below:

STEP1: mknod myfile p

STEP2: chmod 777 myfile

STEP3: compress -v < myfile > myfile.Z &

STEP4: cp -p xyz_file myfile

STEP5: rm myfile

But now my requirement is to have multiple files copied into a directory and compress while the copying is happening so that I dont use a lot of space. Can anyone of you give me some idea of how I can achieve this. For example I want to copy the contents of a directory called source (has file1, file2, file3 and file4) to backup.

Thanks in advance.

Regards

RB
# 2  
Old 01-12-2009
How about...
Quote:
for f in *
do
mknod ${f}_pipe p
chmod 777 ${f}_pipe
compress -v < ${f}_pipe > ${f}.Z &
cp -p $f ${f}_pipe
rm ${f}_pipe
done
# 3  
Old 01-12-2009
Thanks Jerry

But my requirement is to compress the entire directory and not individual files. Although compressing individual files does the job, I will have to make several changes to already existing procedures and scripts for restoring data from the backups, if need arise.

Again thanks for your reply.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Copying Contents of a file

Hello all. Is there a command to copy the contents of one file into another file as the first line? (1 Reply)
Discussion started by: 2metal4u
1 Replies

2. UNIX for Dummies Questions & Answers

How do I compress all files in a directory?

the problem states "Write a script that compresses all the files in the directory. Make a directory and put some files in it. Also make a sub directory in your directory and put files in it also. Once you have this basic ability to compress all files within a directory, add to your script a menu of... (1 Reply)
Discussion started by: Brittany
1 Replies

3. Shell Programming and Scripting

script to compress files in directory that changes its name every day

Hi all I have the following script that should compress a file in a directory: # compress log files older than 2 days find /u01/easydone/DBDUMPS/*.dmp -mtime +2 -exec gzip {} \; BUT the problem is that these files that I want to compress are inside a directory with following format: ... (5 Replies)
Discussion started by: fretagi
5 Replies

4. Shell Programming and Scripting

compress the data and append into a text file

Following is the code: ------------------------------ a=100 b=200 c=300 touch testfl.txt.gz chmod 664 testfl.txt.gz echo $a|gzip >> "testfl.txt.gz" echo $b|gzip >> "testfl.txt.gz" echo $c|gzip >> "testfl.txt.gz" ------------------------------ There is a requirement as follows. I need... (1 Reply)
Discussion started by: kmanivan82
1 Replies

5. UNIX for Dummies Questions & Answers

Help with searching for a file in a directory and copying the contents of that file in a new file

Hi guys, I am a newbie here :wall: I need a script that can search for a file in a directory and copy the contents of that file in a new file. Please help me. :confused: Thanks in advance~ (6 Replies)
Discussion started by: zel2zel
6 Replies

6. Shell Programming and Scripting

Archive directory script with tar/compress

Hi all I need to write a script that archives all files with a certain date in the filename, to another location. It has to run on a AIX using tar/compress or another standard AIX tool. The directory will have x files, each prefixed with a date like yyyymmdd_desc.csv. I need all to... (7 Replies)
Discussion started by: AIXfrog
7 Replies

7. Shell Programming and Scripting

Copying subdirectories of a directory to some other directory and renaming them

Hi, I am a newbie in shell scripting. I have to copy a particular sub-directory (data) from a large no. of directories (all in the same folder) and paste them to another directory ( /home/hubble/data ) and then rename all the subdirectories (data) as the name of its parent directory. please... (8 Replies)
Discussion started by: sholay
8 Replies

8. Shell Programming and Scripting

compress Directory

Hi Friends, I have a directory under which 10 more directories are there. In each 10 directories there are several files. I want to do FTP. But in FTP we cannt Transfer the main directory. each Time we have to go to the respective directry and then we have to to FTP. For this instance I... (9 Replies)
Discussion started by: deep_kol
9 Replies

9. Shell Programming and Scripting

How to Compress files before moving them in a directory

I need a shell script that zips a file before moving them..please help (3 Replies)
Discussion started by: godalle
3 Replies

10. UNIX for Dummies Questions & Answers

How to compress a directory on a Sun Solaris 5.7 ?

Hi, Is there any utility to compress an entire directory on a Sun Solaris 5.7 ? Something like "compressdir" on other flavours of Unix ? Thanks (4 Replies)
Discussion started by: sameerdes
4 Replies
Login or Register to Ask a Question