Operating System - HP-UX
1836647 Members
1644 Online
110102 Solutions
New Discussion

how can I chown, tar, gzip a directory

 
SOLVED
Go to solution
Ragni Singh
Super Advisor

how can I chown, tar, gzip a directory

Hello,

I have a directory that I would like to chown. Then I would like to tar up the dir using relative path and then gzip the dir. Is there a single command that I can use to do all 3 of these please. Any help will be greatly appreciated.
5 REPLIES 5
Patrick Wallek
Honored Contributor
Solution

Re: how can I chown, tar, gzip a directory

That depends on your definition of a single command.

You could write a simple script like:

#!/usr/bin/sh
chown user dir_name
tar -cvf dir_name.tar ./dir_name
gzip dir_name.tar

Be sure to save the script, do a chmod on it to make it executable and then execute it from the command line.

# chmod u+x script_name
# ./script_name

Once it is done:

# ll dir_name.tar.gz

Should show you your gzip'ed tar file.
Mark Greene_1
Honored Contributor

Re: how can I chown, tar, gzip a directory

To chown just the directory do:

chown user:group /dir/path

to chown every file in the directory do:

chown user:group /dir/path/*

to chown every fine in the directory, and every sub-directory and every file in every sub-directory do:

chown -R user:group /dir/path/*

to tar do:

tar /dirpath/targetfile /dirpathsource/*

then to gzip the file you just created with tar:

gzip /dirpath/targetfilefromabove >newfile.gz

obviously, you have to rename all the directory and file references to what's on your system. And while not required, using the .gz extention on the gzip file is recommended.

HTH
mark
the future will be a lot like now, only later
S.K. Chan
Honored Contributor

Re: how can I chown, tar, gzip a directory

Example:- (in /opt, wanted to process dir "ov")

# chown root:sys ov; tar cvf ov.tar ov; gzip ov.tar

Not actually a single command but all commands are in one line. Not sure if this is what you're asking about.
Ragni Singh
Super Advisor

Re: how can I chown, tar, gzip a directory

Thank you very much for all your quick response.
Darrell Allen
Honored Contributor

Re: how can I chown, tar, gzip a directory

Hi Sanman,

In keeping with the one line command and to save disk space, use this:
tar cvf - ./relpath_dir | gzip >output_tarfile.gz

The "intermediate" tarfile is not stored on disk, only the gzipped one. Also, when gzipping a file, the input file is left on disk until the gzip is finished. Thus even more space is used.

The reverse process is:
gzip -dc output_tarfile.gz | tar xf -

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)