tar subdirectories for specific files


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users tar subdirectories for specific files
# 1  
Old 10-12-2006
tar subdirectories for specific files

I have a sample directory structire like following

# pwd
/user/test

and I have files like following

out.txt
A/a.txt
B/b.txt
C/c.txt
(A,B,C are directories )

# tar cvf test.tar *
a A/a.txt 1 blocks
a B/b.txt 1 blocks
a C/c.txt 1 blocks
a out.txt 1 blocks

But whenever I give
# tar cvf test.tar *.txt
a out.txt 1 blocks

My question is when I give "tar cvf test.tar *.txt", why it is not copying all the files like *.txt recursively. How can I tar recursively using wild card.

Regards,
Ronald.
# 2  
Old 10-12-2006
Hi ronald_brayan,
When you give a command like: 'tar cvf test.tar *.txt', what happens is that the shell parses the entire input line. It sees that you are supplying a "*.txt" pattern, so it checks in the current directory for that pattern and replaces that pattern with any files that it finds.

So after the shell is done with the parsing, the command that is executed is:
'tar cvf test.tar out.txt'

In the second case your pattern is just "*". So the shell replaces it with all the files and directories in the current directory. So the command that is executed is the same as:
'tar cvf test.tar A B C out.txt'.

The directories A, B and C and the file out.txt are sent in as args to the tar command, and tar includes any files inside directories in the tar archive. If you put in any more files in the A, B or C directories and run the tar with '*' as the arg, you will find that those files are in the tar archive as well.
# 3  
Old 10-12-2006
tar subdirectories for specific files

Hi blowtorch,

Thanks for your prompt reply.

Is there a way to tar the files from sub-directory also for files like (*.csv).

Because, I can not use * while tar .

Regards,
Ronald.
# 4  
Old 10-12-2006
Oh yeah, I forgot to mention that. You can use find and xargs to do that.

Code:
find . -name *.csv|xargs tar cvf tarfilename.tar

Just know that xargs will handle a very large number of arguments by splitting them up into groups. This won't do what you want. Each new group of files will over write the previous one in the tar file.
# 5  
Old 10-12-2006
Tar files

Hi blowtorch,

Thanks a lot . It Worked.

Regards,
Ronald.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Linux read specific content file from tar.gz files without extracting

hello i wish to write the result of these below conditions in a file: 1. in a specific folder, i have many tar.gz files. 2. each tar.gz file contains ".dat" file in sub folders. 3. i wish to get the full path of these .dat files, if i find in it a specific word ("ERROR24"). 4. all this... (6 Replies)
Discussion started by: jimmyjames9
6 Replies

2. Shell Programming and Scripting

Insert a newline after match in files of specific name under some subdirectories?

Hi I'd like to add the newline: \tuser: nobody", or "<TAB>user: nobody to all files named: docker-compose.ymlin subfolders of pwd with names beginning with 10-20. Within these files, I'd like to find the line (there'll only be one) containing: command: celery workerNOTE: As far as... (2 Replies)
Discussion started by: duncanbetts
2 Replies

3. Shell Programming and Scripting

Append string to all the files inside a directory excluding subdirectories and .zip files

Hii, Could someone help me to append string to the starting of all the filenames inside a directory but it should exclude .zip files and subdirectories. Eg. file1: test1.log file2: test2.log file3 test.zip After running the script file1: string_test1.log file2: string_test2.log file3:... (4 Replies)
Discussion started by: Ravi Kishore
4 Replies

4. Shell Programming and Scripting

Bash script deleting my files, and editing files in subdirectories question

#!/bin/bash # name=$1 type=$2 number=1 for file in ./** do if then filenumber=00$number elif then filenumber=0$number fi tempname="$name""$filenumber"."$type" if (4 Replies)
Discussion started by: TheGreatGizmo
4 Replies

5. 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

6. Shell Programming and Scripting

Find *.tar files under all subdirectories

Hi there, I'm new to shell scripting... I've a situation like to find *.tar files under all subdirectories in "/home/abcd" and i used the below, find /opt/lhapp ! -name "temp" | more the above works fine.. Now don't need search few direcotries like "/home/abcd/aaaa",... (15 Replies)
Discussion started by: skcvasanth
15 Replies

7. UNIX for Dummies Questions & Answers

Extracting specific files from a tar file in HP-UX

I have tried: tar -xfv mytarfile.tar archive/tabv/* tar -xfv mytarfile.tar --wildcards 'archive/tabv/*' tar -xf mytarfile.tar -v --wildcards 'archive/tabv/*' tar -xfv mytarfile.tar --wildcards --no-anchored 'archive/tabv/*' tar -xfv mytarfile.tar --wildcards `archive/tabv/*` and none... (5 Replies)
Discussion started by: zapper222
5 Replies

8. Shell Programming and Scripting

Finding file in specific subdirectories

Hi experts problem: i have a directory "DATA" with lots of subdirectories named as date with hudge data containning files. Directory = "DATA" subdirectory = "20090611" & "20090612" ...... 20090611 = thousands of files i wanna apply find command to find all files in... (3 Replies)
Discussion started by: The_Archer
3 Replies

9. UNIX for Dummies Questions & Answers

tar archive with including specific patern files

Hi, I need to create recursive tar archive, while I put there only files of type a*.txt. Without file filtering the command is: tar cfzf test.tar.gz test_tar/ How I include the switch for including only files with pattern a*.txt ? Thanks a lot! (1 Reply)
Discussion started by: john.gelburg
1 Replies

10. Filesystems, Disks and Memory

tar: how to exclude subdirectories?

If i have a bunch of directories that i normally backup with this: tar cvhf /dev/rmt/0 /export/home How can i exclude certain subdirectories under the /export/home? tar cvhf /dev/rmt/0 /export/home | grep -v 'test' ? will that exclude anything named test, and any subdirectories under test? (7 Replies)
Discussion started by: kymberm
7 Replies
Login or Register to Ask a Question