tar file from current folder


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers tar file from current folder
# 1  
Old 07-07-2011
tar file from current folder

Hello guys,

I am sure this has been asked before, but honestly, I cant find post talking about it.

Here is what I need:

- A tar file will be generated manually by user
- This tar file is then used within a bash shell script

My source folder structure is like this:

Code:
 
/basepath/day1
/basepath/day2
/basepath/day3

So, in a folder, I do have several subfolders. On each of these subfolders, I do have files and more subfolders

I want to tar the content of one of these 'day' folders, but the two ways I tried are:

Code:
 
(placed in /basepath/day1):
tar -zcf day1.tar.gz .

Result is that tar.gz file is added to the same tar.gz file itself. These causes problem when uncompressing

Code:
 
(placed in /basepath/):
tar -zcf day1.tar.gz ./day1

This is causing, that, when I untar the file in a tmp directory, all is included in the day1 directory, this way:

Code:
 
tar -zxf ./day1.tar.gz -C /tmp

What I got is:

/tmp/day1/.....

My script is expecting content in /tmp without any more subfolders


Any advise you can give me guys?
Basically what I am trying to get is just similar as we do in windows: we zip files and folders, and the unzip them in any other folder without informaton from absolute paths

So getting this:

From:
/basepath/day1/file1
/basepath/day1/file2
/basepath/day1/subfolder/file3
/basepath/day1/subfolder/file4

To this:
/tmp/file1
/tmp/file2
/tmp/subfolder/file3
/tmp/subfolder/file4

And not this
/tmp/day1/file1
/tmp/day1/file2
/tmp/day1/subfolder/file3
/tmp/day1/subfolder/file4

As I said, if I tar with first option (tar -zcf day1.tar.gz .) I got the file tar.gz itself compressed. When uncompressing, I am getting some "you cant use utime" error

I hope I could explain myself

Thanks a lot in advanced!
# 2  
Old 07-07-2011
I'm confused.
Say you have directories like this
Code:
month
  day1
  day2

IF you want a tar ball of /month/day1, with the tar ball IN that same directory:
Code:
tar zvfc /tmp/month.day1.tar  /month/day1
cp /tmp/month.day1.tar  /month/day1/month.day1.tar

That creates a tar archive with an absolute path, which is not all that useful for some things.

This creates a relative path:

Code:
cd /month
tar zvfc /tmp/month.day1.tar  ./day1
cp /tmp/month.day1.tar  /month/day1/month.day1.tar

# 3  
Old 07-08-2011
Thanks for the answer, I will try to make this clearer

I do have the following structure:

/backups/20110701
/backups/20110702
/backups/20110703
...

On each date folder, I do have

/backups/20110701/scripts
/backups/20110701/templates
/backups/20110701/file.txt

Inside 'scripts' and 'templates' there are files, but no more subfolders

I would like to have a 20110701.tar.gz file, when, untar in /tmp, resulted in this:

/tmp/scripts
/tmp/templates
/tmp/file.txt

instead of

/tmp/20110701/scripts
/tmp/20110701/templates
/tmp/20110701/file.txt

If I create the tar file being at /backups/20110701 in this way:

Code:
tar -zcf 20110701.tar.gz .

The tar.gz file is added again in the tar file, so when I list content, I get:

tar -tl 20110701.tar.gz
./scripts
./templates
./file.txt
./20110701.tar.gz

This is causing me problems when uncompressing

Can you help?

Thanks a lot
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Do I need to extract the entire tar file to confirm the tar folder is fine?

I would like to confirm my file.tar is been tar-ed correctly before I remove them. But I have very limited disc space to untar it. Can I just do the listing instead of actual extract it? Can I say confirm folder integrity if the listing is sucessful without problem? tar tvf file1.tar ... (1 Reply)
Discussion started by: vivien_chu
1 Replies

2. UNIX for Dummies Questions & Answers

Tar command to preserve the folder/file arrangement

Hi, I do have question for un tar a file. I have several 'tar'ed files. For example: SRS.tar.bz2. I was trying to untar them in a linux server using the command: tar xvjf SRS.tar.bz2 It worked perfectly. but when I open this file in my mac computer all the files are extracted into a... (7 Replies)
Discussion started by: Lucky Ali
7 Replies

3. UNIX for Dummies Questions & Answers

Search current folder and subfolders with grep

Hello, Neither ‘Grep -r' nor ‘grep -R' is working in my environment. (Searching for a text pattern in the files) Any suggestions... Using SunOS 5.9 Thanks, Trinanjan. (1 Reply)
Discussion started by: bhanja_trinanja
1 Replies

4. Shell Programming and Scripting

Getting current folder name appended to all desired files

Hello everyone, Just registered here, I'm kinda new to Unix :o I've been trying to automate some processes with various Windows tools. I found that using unix scripts the result would be closest to my needs. So I installed Cygwin on Windows 7. My folders and files are structured like this:... (7 Replies)
Discussion started by: c_bg1
7 Replies

5. UNIX for Dummies Questions & Answers

tar -cvf test.tar `find . -mtime -1 -type f` only tar 1 file

Hi all, 4 files are returned when i issue 'find . -mtime -1 -type f -ls'. ./ora_475244.aud ./ora_671958.aud ./ora_934052.aud ./ora_934050.aud However, when I issued the below command: tar -cvf test.tar `find . -mtime -1 -type f`, the tar file only contains the 1st file -... (2 Replies)
Discussion started by: ahSher
2 Replies

6. UNIX for Dummies Questions & Answers

Jar/Tar to a diffent folder/same folder w/ filename

Hi, I want to extract myfile.war to a folder which is in the same folder with war file.I did this as normal: jar -xvf myfile.war But it exploded all the content of file to the same level folder instead of that I was expecting to create a folder called myfile. This works with tar: ... (0 Replies)
Discussion started by: reis3k
0 Replies

7. Shell Programming and Scripting

How to find files in current folder only?

How do I find files in current folder only? We are on AIX 5.3, so maxdepth is not supported. I tried to do this find /dir1/dir2/dir3/dir4 -prune -type f to display all files in /dir1/dir2/dir3/dir4 only but it does not show any files. Somehow the -prune option works for dir3 level... (7 Replies)
Discussion started by: Hangman2
7 Replies

8. Shell Programming and Scripting

Use awk to create new folder in current directory

Alright, I am sure this is a laughable question, but I don't know so I am going to ask anyway. I have a little script I am writing to take information from one source, recode it in a certain way, and print to files for each subject I have data for. This all works perfectly. I just want to put... (6 Replies)
Discussion started by: ccox85
6 Replies

9. UNIX for Dummies Questions & Answers

Pack current folder

How do I pack (using tar zcvf ?) the current folder inluding all files and folders ?? I need to be sure to get all files and folders/subfolders... Later I will unpack into a new folder on a new server.. Appreciate any help.. (3 Replies)
Discussion started by: WebWatch
3 Replies

10. UNIX for Dummies Questions & Answers

Using tar for current directory, but not subs

I know that I can type tar -cvf myfile.tar * to tar the current directory and all it's sub directories, but how do I tar ONLY the current directory and skip all the subdirectories? (3 Replies)
Discussion started by: beilstwh
3 Replies
Login or Register to Ask a Question