Solved

How do you tar a sequential file

Posted on 2011-09-17
9
407 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 10

Accepted Solution

by:
acbxyz earned 500 total points
ID: 36554022
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
ID: 36554105
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
ID: 36554285
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:SuperRoot
ID: 36554405
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
 
LVL 10

Assisted Solution

by:acbxyz
acbxyz earned 500 total points
ID: 36554432
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
ID: 36554495
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
ID: 36554548
YES! that works!! Man you are a life saver
0
 
LVL 21

Expert Comment

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

Expert Comment

by:Tintin
ID: 36554827
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to know the backup date of a restored DB? 4 80
Understanding ping command in Ubuntu 5 68
how to send mail in unix 2 50
linux convert text file to PDF 7 73
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…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

752 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