Tar extract a multiple directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Tar extract a multiple directories
# 1  
Old 06-12-2015
Tar extract a multiple directories

i extract it through script, is there any way to script or automate to tar extract a tarfiles in multiple directories at once?

Cannot open: No such file or directory
tar: Error is not recoverable: exiting now



Code:
for dir in `ls -d /tarfiles/*/ | sed 's/.$//'`
do
rm -f $dir/*.tar
mv -f $dir*tgz* $dir/
gunzip $dir/*.tgz
#done


for f in `ls -l $dir/*.tar`
#f=`ls -l $dir/*.tar`
do
tar xvf  "$dir/$f"  -C $dir/

# 2  
Old 06-30-2015
It's not immediately obvious from the script what the directory and file structure you are working with looks like. Based on the first line, it looks like you have a number of directories in /tarfiles, each directory can contain one of more tar files which you immediately delete.
Next, you are looking for tar gz files that are in the /tarfiles directory and are named after each subdirectory, and then moving them into that subdirectory, it looks like there could be more than one per directory.
Once all that's done, you are unzipping the tar gzs, and then untaring them.

If all that is true, then we can proceed.

Each of the files returned by your for loop will already have the right directory included in it, you are then prepending the directory name again. You'd end up with something like /tarfiles/abcd/abcd/abcd-foo.tar when you actually want /tarfiles/abcd/abcd-foo.tar - thus tar saying it can't find the file.

If that's indeed what's happening, just remove the $dir part of the input file being passed to tar.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract a tar ball into multiple directories

#cat a BAC064DAL BAC063DAL BAC056PHX BAC066DAL BAC062PHX BAC062DAL BAC060DAL BAC058PHX BAC054PHX BAC051PHX # for i in `cat a` > do > tar xvf $a/$a*.tar* > done tar: /*.tar*: Cannot open: No such file or directory tar: Error is not recoverable: exiting now tar: /*.tar*: Cannot... (3 Replies)
Discussion started by: kenshinhimura
3 Replies

2. UNIX for Dummies Questions & Answers

Do I need to extract the entire tar file to confirm the tar folder is fine?

I would like to confirm my file.tar is been tar-ed correctly before I remove them. But I have very limited disc space to untar it. Can I just do the listing instead of actual extract it? Can I say confirm folder integrity if the listing is sucessful without problem? tar tvf file1.tar ... (1 Reply)
Discussion started by: vivien_chu
1 Replies

3. UNIX for Dummies Questions & Answers

Deleting multiple directories inside multiple directories

Hi, Very unfamiliar with unix/linux stuff. Our admin is on vacation so, need help very quickly. I have directories (eg 40001, 40002, etc) that each have one subdirectory (01). Each subdir 01 has multiple subdirs (001, 002, 003, etc). They are same in each dir. I need to keep the top and... (7 Replies)
Discussion started by: kkouraus1
7 Replies

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

5. Solaris

How to extract files from a tar file without creating the directories?

Hello all. I have a tar file that contains a number of files that are stored in different directories. If I extract this tar file with -xvf , the directories get created. Is there a way to extract all of the files into one directory without creating the directories stored in the tar file. (9 Replies)
Discussion started by: gkb
9 Replies

6. Shell Programming and Scripting

check if multiple directories exist else create missing directories

Hi , I 'm trying to check if multiple directories exist on a server, if not create the missing ones and print " creating missing directory. how to write this in a simple script, I have made my code complex if ; then taskStatus="Schema extract directory exists, checking if SQL,Count and... (7 Replies)
Discussion started by: ramky79
7 Replies

7. Linux

extract glibc-2.3.2.tar.tar

Hi, how can I extract glibc-2.3.2.tar.tar file ? I used tar -xf but does not work. Thank you. (4 Replies)
Discussion started by: big123456
4 Replies

8. UNIX for Dummies Questions & Answers

tar, zip multiple separate directories and move the results to another volume

TIA, I'm using FreeBSD 6 I have a series of Directories (A,B,C,...Z). Each directory has files and other directories within it. I want to compress the contents of each top directory into a single file so that I get an archive of each directory (for example, A.gzip) AND and want to move... (5 Replies)
Discussion started by: jccbin
5 Replies

9. UNIX for Advanced & Expert Users

How to create a Tar of multiple Files in Unix and FTP the tar to Windows.

Hi, On my Unix Server in my directory, I have 70 files distributed in the following directories (which have several other files too). These files include C Source Files, Shell Script Source Files, Binary Files, Object Files. a) /usr/users/oracle/bin b) /usr/users/oracle... (1 Reply)
Discussion started by: marconi
1 Replies

10. BSD

tape drives vs. tar with multiple directories

Hello, I have a little problem with backup & restoring files from tape drive. I am adding 3 directories to my tape, and it is OK: hades# tar -cvf /dev/nsa0 test test1 restore a test a test/level1 a test/myharddisk.img a test1 a test1/level1 a test1/myharddisk.img a test1/test.img a... (1 Reply)
Discussion started by: d3m00n
1 Replies
Login or Register to Ask a Question