Solved

How do you tar a sequential file

Posted on 2011-09-17
9
393 Views
Last Modified: 2012-05-12
I have multiple files starting from test.file1 and ends at test.file890. I need to tar test.file122 to test.file300. I can't just type them all because its a lot to type in. What can I do to easily tar my needed files?

0
Comment
Question by:SuperRoot
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 10

Accepted Solution

by:
acbxyz earned 500 total points
Comment Utility
You can use a little bash-script to do that
tar -cxf tarfile.tar.gz $(for i in `seq 122 300`; do echo -n "test.file$i "; done)

Open in new window


If your command gets too long for cmdline it is also possible to update the tar file for each file.
tar -cf tarfile.tar file.test122
for i in `seq 123 300`; do
tar -uf tarfile.tar test.file$i
done
gzip tarfile.tar

Open in new window

0
 
LVL 1

Author Comment

by:SuperRoot
Comment Utility
this is what I get tar:

tar: test.fileseq: Cannot stat: No such file or directory
tar: 1: Cannot stat: No such file or directory
tar: 167: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors
0
 
LVL 10

Expert Comment

by:acbxyz
Comment Utility
This error means you forgot the backticks around the seq-command or more probably used single quotes instead. In English layout, the backticks are found on the left upper corner between the escape key and the tab key.
With backticks bash starts a new process with the command line inside these backticks and uses its output instead.
For testing you can type only "seq 1 167" on terminal and should get a list of numbers starting at 1 forward to 167.
0
 
LVL 1

Author Comment

by:SuperRoot
Comment Utility
Hi acbxyz,

this is exactly what I did:

tar -czvf drive.cap.tar.gz drive.cap.test
for i in `seq 1 167`; do
tar -uvf drive.cap.tar.gz drive.cap.test$i
done

when I press enter, I get the error:
tar: test.fileseq: Cannot stat: No such file or directory
tar: 1: Cannot stat: No such file or directory
tar: 167: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors

I'm sorry if it sounds stupid but the commands above should have worked right?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 10

Assisted Solution

by:acbxyz
acbxyz earned 500 total points
Comment Utility
Yes, this should work. Actually, it doesn't because tar doesn't support updates on compressed archives, but it should print that it can't; 167 times.

Which shell do you use? "help" may help you ;-)
Maybe it'll help replacing the for-line with this, when your shell doesn't support subshells via backtick:
for i in $(seq 1 167); do

Open in new window

0
 
LVL 21

Expert Comment

by:Papertrip
Comment Utility
user@box:~$ touch a1 a2 a3
user@box:~$ tar cvf abc.tar a[2-3]
a2
a3
user@box:~$

Open in new window

0
 
LVL 1

Author Closing Comment

by:SuperRoot
Comment Utility
YES! that works!! Man you are a life saver
0
 
LVL 21

Expert Comment

by:Papertrip
Comment Utility
Did you try my command?  A bit cleaner solution...
0
 
LVL 48

Expert Comment

by:Tintin
Comment Utility
Here's another alternative which is much more efficient



tar czvf file.tar.gz $(seq 122 1300 | xargs -i echo  test.file.{})

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now