Solved

How do you tar a sequential file

Posted on 2011-09-17
9
413 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
WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

 
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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.
Suggested Courses

622 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