tar -C syntax question

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting tar -C syntax question
# 1  
Old 09-01-2011
tar -C syntax question

I am writing a perl script to tar multiple files (in unix) from a given directory to a given output directory. I do NOT want the file path included in the tar, so I've flagged the -C option. Example:
tar -cvf tar/1.tar -C htmp/source/ 1-1-1.xml

However, I need to do this for a number of target files from the same directory. I've found that if I just specify another -C flag I can do a second file, like:
tar -cvf tar/1.tar -C htmp/source/ 1-1-1.xml -C htmp/source/ 1-1-19.xml

but this seems way too long, considering the number of files in the given directory. I'm wondering if anyone knows of a syntax shortcut to get all the files in this directory, without having to flag -C for each one.


---------- Post updated at 12:27 PM ---------- Previous update was at 12:17 PM ----------

Heh... nvm I found the answer. Just looked at man tar:
"If file is `.', archive all files in directory."
RTFM, I guess.

tar -cvf tar/1.tar -C htmp/source/ .

grabs everything.

# 2  
Old 09-01-2011
Just one -C ought to do.

The second -C probably isn't doing anything since these are relative paths -- it moves from ./ into ./html/source the first time, tries to chdir into ./htmp/source/htmp/source/ and complain no such directory, and still adds 1-1-19.xml because it's dir didnt' change since the first -C.
# 3  
Old 09-01-2011
that's what i thought at first, too, but that wasn't working either:
> tar -cvf tar/1.tar -C hmtp/source/ 1-1-1.xml 1-1-19.xml
a 1-1-1.xml 6K
tar: 1-1-19.xml: No such file or directory

I figured it out though, see my update.
# 4  
Old 09-01-2011
If you really want to archive the whole folder, just tar -cf file.tar /path/to/folder/, no -C necessary. I was assuming you just wanted all xml files in the folder or something.

The -C difference is interesting. My version of tar stays chdir-ed after -C.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Question regarding quotation syntax

Hey guys, my first post on UNIX Forums(much overdue IMO)! I've got this bit of code that doesn't seem to be working correctly for an Android app I'm working on: "screen -S gmod1 -p 0 -X stuff " & "" & command.text & "`echo -ne '\015'`""" Basically it types command.text(variable determined... (4 Replies)
Discussion started by: stingwraith
4 Replies

2. Shell Programming and Scripting

A Perl Syntax Question.

Greetings! Here's what I believe is a "simple one" for the community tonight ;) What I'm trying to do is assign a "true/false" value to a variable depending upon whether a named process (some-process) exists; and then test for this value in the succeeding logic. I banged my head against the... (2 Replies)
Discussion started by: LinQ
2 Replies

3. Programming

Perl syntax question

Hallo everybody, I have a following problem - I'm doing a map funciont to fill in a HTML table and I want to use some radiobutton groups. Unfortunatelly, they are grouped by names, so I have to add some "counter" that will divide one row from another, and I'm using CGI.pm for generating the... (3 Replies)
Discussion started by: duskos
3 Replies

4. Shell Programming and Scripting

Question about syntax error

first of all.. sorry about all the question bombing.. im bored atm so im currently playing around with sh scripting hehe s = `expr ls -s Documents | grep Music | awk '{ print $1 }' ` t = `expr $t + $s` it give syntax error s not found t not found lol... any idea why? (7 Replies)
Discussion started by: Nick1097
7 Replies

5. UNIX for Dummies Questions & Answers

Dot and redirected output syntax in a tar command

Hi All, Please could anyone advise what the purpose of the dot syntax in the following command means: tar -cvf ${WORKING_BACKUP_ROOT}/${TAR_ARCHIVE_FILE} . >/${BACKUP_ROOT}/${ARCHIVE_LOG} Many thanks (2 Replies)
Discussion started by: daveu7
2 Replies

6. Shell Programming and Scripting

Some help with tar options and syntax?

I've got a script that's first copying a list of files into /etc/confbackups after running some other stuff, I'm having trouble with tar now though. What I've got: tar -cCf $date.$list.tar.gz /etc/confbackups *.conf What I'm thinking this is supposed to do is create the archive as specified,... (4 Replies)
Discussion started by: Jandiedonkerman
4 Replies

7. Shell Programming and Scripting

awk syntax question

Hi I use awk command to delete the first blanc line of a file: awk '/^$/ && !f{f=1;next}1' infile > outfile can somebody please explain me what the last "1'" in !f{f=1;next}1' stands for... Thansk a lot -A (3 Replies)
Discussion started by: aoussenko
3 Replies

8. UNIX for Dummies Questions & Answers

AWK syntax question

Hi, Have to check file names in some given directory. SO, What is the right syntax here: *$3*=="'$object_list'" - just wanted to check if $3 is in the object_list. And also, Do I need so many quotes around? (5 Replies)
Discussion started by: Leo_NN
5 Replies

9. Shell Programming and Scripting

awk syntax question

Hi there could someone explain what is happening in the following function/statement for me, im just a little confused code = 'BEGIN{FS=","} { printf ("%-11s,%s%s%s,%07.2f,%14s,%-3s\n",$1,substr($2,9,2),substr($2,6,2),substr($ 2,3,2),$9,$10,$12) } this function is called later in the... (2 Replies)
Discussion started by: hcclnoodles
2 Replies

10. UNIX for Dummies Questions & Answers

Syntax for tar command

I am trying to extract a file using tar. I cd'ed to the directory I wanted to start in. I had the tar file in the same directory. I executed tar xvf filename . It appeared that it was extracting into the directory the tar file was created from instead of into the directory I was in. How do I... (1 Reply)
Discussion started by: baunocj
1 Replies
Login or Register to Ask a Question