Tar creating copies of files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Tar creating copies of files
# 1  
Old 07-18-2012
Tar creating copies of files

I am trying to archive directories based on their last modified date. When I tar and compress the directory it makes copies of whats inside, I don't know how to fix this.

Here is my code.

Code:
#!/bin/bash
#AUTODRUNDISABLE
VERSION="0.2"

cd /desired/directory/to/archive
find . -type d -newermt 2012-06-01 ! -newermt 2012-06-30 | tar -zcvf tar.tar.gz

I made a test directory because the actual directories I will be working with are massive and so to same time in compression I created /test/sub_dir/test.txt.

When I run my script this is what it compresses.
./test/
./test/sub_dir/
./test/sub_dir/test.txt
./test/sub_dir/
./test/sub_dir/test.txt

Why am I getting copies?

Also I'm on Ubuntu 12.04
# 2  
Old 07-18-2012
Code:
find . -type d -newermt 2012-06-01 ! -newermt 2012-06-30 | tar -zcvf tar.tar.gz

Pretty sure you're having a problem because you aren't using an or or and in y our find, but I'm not 100% sure.

My test (I don't have the same find flags you do):

Code:
$ touch --date "2010-01-05" /tmp/old.foo
$ touch --date "2010-01-01" /tmp/older.foo
$ touch --date "2010-01-03" ./sub_dir/test.txt 
$ touch --date "2010-01-03" ./sub_dir/test.txt
$ find . \! -newer /tmp/old.foo -a -newer /tmp/older.foo -print
./sub_dir/test.txt
$ find . \! -newer /tmp/old.foo -a -newer /tmp/older.foo -exec tar -zcvf tartest.tar.gz {} \;
./sub_dir/test.txt

works as expected. Note the -a for the 'and' conditional.
# 3  
Old 07-18-2012
I'm not sure that any of the above commands really work... Not because the find doesn't work, but because of the way you're using tar.

Ordinary tar does not read filenames from standard input. I think GNU tar can but that's an extension.

Vryali's find will run tar once for each individual file, overwriting the tarball every time -- almost certainly not what you want.

Change it a bit to dump more than one file into tar like so:

Code:
find . \! -newer /tmp/old.foo -a -newer /tmp/older.foo | xargs -rcf file.tar
gzip file.tar

Note that, given enough files, xargs will run tar more than once, ergo you have to use the 'append' mode to get a valid file when that happens. You can't append a compressed file, so you have to compress afterwards.
# 4  
Old 07-18-2012
I changed the
Code:
-type d

to
Code:
-type f

and that did the trick, grabbing the directory and everything in it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Finding copies of files

theres a situation i'm dealing with where i feel like folks are stealing some of my files. they copy it (because they have complete sudo root access like i do) from my home directory and they copy it wherever and then change the name of the file so i wont know that they have it. is there a way... (1 Reply)
Discussion started by: SkySmart
1 Replies

2. Windows & DOS: Issues & Discussions

[SOLVED] Creating .tar file

Hi, How to create a .tar file in windows OS.. I need to ftp tat <filename>.tar file into AIX and untar it there and will use for futher actions.. Please help.. Thanks in advance.. (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

3. UNIX for Dummies Questions & Answers

Creating a TAR

Hello , I have a unix script to create a TAR which is invoked from Mainframe job. #!/bin/ksh echo "Start Time : " $(date +%m-%d.%H.%M.%S) echo "*************************" tdate=$(date +_%m%d_%H%M%S) cmdfil="/usr/lpp/web-data/mfg/nct/file-data/ftpcmd.dat"... (6 Replies)
Discussion started by: gayathrivm
6 Replies

4. Shell Programming and Scripting

tar command to explore multiple layers of tar and tar.gz files

Hi all, I have a tar file and inside that tar file is a folder with additional tar.gz files. What I want to do is look inside the first tar file and then find the second tar file I'm looking for, look inside that tar.gz file to find a certain directory. I'm encountering issues by trying to... (1 Reply)
Discussion started by: bashnewbee
1 Replies

5. Solaris

How to extract files from a tar file without creating the directories?

Hello all. I have a tar file that contains a number of files that are stored in different directories. If I extract this tar file with -xvf , the directories get created. Is there a way to extract all of the files into one directory without creating the directories stored in the tar file. (9 Replies)
Discussion started by: gkb
9 Replies

6. UNIX for Dummies Questions & Answers

Creating a Tar file while files are spooling

Hi I have done a search for this but couldn't find much on it. I am creating a tar file with the command below tar cvf /export/home/user/backup/*Will this is being created I have a job spooling to 5 texts files in the following directory /export/home/user/backup/STATS/ The tar files... (1 Reply)
Discussion started by: sgarvan
1 Replies

7. OS X (Apple)

Terminal.app keeps creating copies of my settings files

Under Leopard, I like to conveniently open Terminal windows onto remote systems. I've created several settings files in Terminal, one for each remote system that I want to access. To open window, I right-click on the Terminal icon in the Dock, expand the "New Window" menu item, and select the... (0 Replies)
Discussion started by: siemsen
0 Replies

8. Shell Programming and Scripting

Creating tar excluding links

hi, How do i create a tar file of a directory excluding the links in that particular directory and its sub-directories. The below command doesnt work for me. tar -cvf abc.tar /dir1 --exclude"^l" (1 Reply)
Discussion started by: yesmani
1 Replies

9. UNIX for Advanced & Expert Users

How to create a Tar of multiple Files in Unix and FTP the tar to Windows.

Hi, On my Unix Server in my directory, I have 70 files distributed in the following directories (which have several other files too). These files include C Source Files, Shell Script Source Files, Binary Files, Object Files. a) /usr/users/oracle/bin b) /usr/users/oracle... (1 Reply)
Discussion started by: marconi
1 Replies

10. UNIX for Dummies Questions & Answers

extract tar files without creating directory

I received a tar file of a directory with 50,000 files in it. Is it possible to extract the files in the tar file without first creating the directory? ie. Doing tar -xvf filename.tar extracts as follows: x directory/file1.txt x directory/file2.txt . . . I would like to avoid... (4 Replies)
Discussion started by: here2learn
4 Replies
Login or Register to Ask a Question