LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-23-2016, 07:42 AM   #1
chris_crunch
Member
 
Registered: Jan 2016
Location: Braintree, Essex
Distribution: Ubuntu 14.04
Posts: 107

Rep: Reputation: Disabled
Mass opening of .tar files?


Hi, another question on tar files.
I have 982 similar .tar file on my computer, all containing JPEG images I wish to extract.
For example, here are some:

Code:
02088466.tar  n02113186.tar  n02480495.tar  n02917067.tar  n03400231.tar  n03788195.tar  n04118776.tar  n04482393.tar  n09229709.tar
n01748264.tar                      n02088632.tar  n02113624.tar  n02480855.tar  n02927161.tar  n03404251.tar  n03788365.tar  n04120489.tar  n04483307.tar  n09246464.tar
n01749939.tar                      n02089078.tar  n02113712.tar  n02481823.tar  n02930766.tar  n03417042.tar  n03791053.tar  n04125021.tar  n04485082.tar  n09256479.tar
n01751748.tar                      n02089867.tar  n02113799.tar  n02483362.tar  n02939185.tar  n03424325.tar  n03792782.tar  n04127249.tar  n04486054.tar  n09288635.tar
n01753488.tar                      n02089973.tar  n02113978.tar  n02483708.tar  n02948072.tar  n03425413.tar  n03792972.tar  n04131690.tar  n04487081.tar  n09332890.tar
n01755581.tar                      n02090379.tar  n02114367.tar  n02484975.tar  n02950826.tar  n03443371.tar  n03793489.tar  n04133789.tar  n04487394.tar  n09399592.tar
n01756291.tar                      n02090622.tar  n02114548.tar  n02486261.tar  n02951358.tar  n03444034.tar  n03794056.tar  n04136333.tar  n04493381.tar  n09421951.tar
n01768244.tar                      n02090721.tar  n02114712.tar  n02486410.tar  n02951585.tar  n03445777.tar  n03796401.tar  n04141076.tar  n04501370.tar  n09428293.tar
n01770081.tar                      n02091032.tar  n02114855.tar  n02487347.tar  n02963159.tar  n03445924.tar  n03803284.tar  n04141327.tar  n04505470.tar  n09468604.tar
n01770393.tar                      n02091134.tar  n02115641.tar  n02488291.tar  n02965783.tar  n03447447.tar  n03804744.tar  n04141975.tar  n04507155.tar  n09472597.tar
n01773157.tar                      n02091244.tar
I can't find such a command to open all of them at once, but surely one must exist?

As in, it would be good to just simply turn these .tar files into directories containing the images.

Last edited by chris_crunch; 02-23-2016 at 07:49 AM.
 
Old 02-23-2016, 07:51 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-30
Posts: 5,289

Rep: Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916
something like this mite work
Code:
[schneidz@hyper temp]$ ll
total 8
-rw-rw-r--. 1 schneidz schneidz 1010 Feb 23 07:49 temp1.tar
-rw-rw-r--. 1 schneidz schneidz 1397 Feb 23 07:49 temp2.tar
[schneidz@hyper temp]$ for tar in *.tar 
do
 tar -xvjf $tar
done
zorin.dw
scientific.dw
 
Old 02-23-2016, 07:52 AM   #3
chris_crunch
Member
 
Registered: Jan 2016
Location: Braintree, Essex
Distribution: Ubuntu 14.04
Posts: 107

Original Poster
Rep: Reputation: Disabled
Like, I tried using wildcards but is there a reason why this isn't working?

Code:
 chris@chris-crunch:/data1/IMAGENET/training_data$ sudo tar xvf n*.tar -C images
tar: n01443537.tar: Not found in archive
tar: n01484850.tar: Not found in archive
tar: n01491361.tar: Not found in archive
...
 
Old 02-23-2016, 07:53 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 15,646

Rep: Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129
I have no idea if there was any directory structure stored inside those tar files, but something like this may work:
Code:
for a in *.tar
do
   mkdir /something/$a
   tar -C /something/$a -xf $a
done
obviously you need to check it first and find space for those images (otherwise you will get a disk full again)
 
1 members found this post helpful.
Old 02-23-2016, 07:58 AM   #5
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: root
Distribution: Slackware & BSD
Posts: 1,667

Rep: Reputation: 494Reputation: 494Reputation: 494Reputation: 494Reputation: 494
To open all at once, open a terminal in, or cd to, the folder containing all the tar files you wanted to open, then issue:
Quote:
tar -xf ./*tar
don't omit the period before the bar "./" indicating that you are issuing the command over the files "inside" the folder. However, if you wanted to do it by cumulation, here is an example:
Quote:
tar -xf n01*tar
tar -xf n02*tar
tar -xf no3*tar
and so on....as you wish.
that will untar files beginning "n01......tar" and files "n02.......tar" separately. That if you wish to.

Hope that helps. Good luck.

m.m.
 
Old 02-23-2016, 08:02 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 15,646

Rep: Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129
that does not work the first argument is the tar file to unpack the other ones are the files to pick from the tar.
You cannot specify several archives
 
Old 02-23-2016, 08:06 AM   #7
chris_crunch
Member
 
Registered: Jan 2016
Location: Braintree, Essex
Distribution: Ubuntu 14.04
Posts: 107

Original Poster
Rep: Reputation: Disabled
Hmm idk man, it works individually...

Code:
chris@chris-crunch:/data1/IMAGENET/training_data$ sudo tar xvf n02134084.tar -C images
n02134084_13932.JPEG
n02134084_10275.JPEG
n02134084_24140.JPEG
n02134084_21321.JPEG
n02134084_16632.JPEG
n02134084_20812.JPEG
n02134084_21413.JPEG
n02134084_7790.JPEG
n02134084_20942.JPEG
...
But do it all at once and this happens

Code:
chris@chris-crunch:/data1/IMAGENET/training_data$ for a in *.tar; do    mkdir /something/$a;    tar -C /something/$a -xf $a; done
mkdir: cannot create directory ‘/something/ILSVRC2012_img_train(0)(0)(0).tar’: No such file or directory
tar: /something/ILSVRC2012_img_train(0)(0)(0).tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
mkdir: cannot create directory ‘/something/ILSVRC2012_img_train_t3.tar’: No such file or directory
tar: /something/ILSVRC2012_img_train_t3.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
mkdir: cannot create directory ‘/something/n01440764.tar’: No such file or directory
tar: /something/n01440764.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
mkdir: cannot create directory ‘/something/n01443537.tar’: No such file or directory
tar: /something/n01443537.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
mkdir: cannot create directory ‘/something/n01484850.tar’: No such file or directory
tar: /something/n01484850.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
...
What does that mean?
 
Old 02-23-2016, 08:07 AM   #8
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 15,646

Rep: Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129
you have forgotten to replace /something you need to enter your destination directory (and also create that dir first - if not yet created)
 
Old 02-23-2016, 08:07 AM   #9
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,866

Rep: Reputation: 1487Reputation: 1487Reputation: 1487Reputation: 1487Reputation: 1487Reputation: 1487Reputation: 1487Reputation: 1487Reputation: 1487Reputation: 1487
The closest you will get to something like what you describe is either an explicit loop as shown in other posts

or using find: "find *.tar -exec tar -xf '{}' ';'", which will pass each individual tar file found to the tar command (via the '{}'). This is equivalent to the loops, just a bit shorter to type as a single command line.
 
Old 02-23-2016, 08:18 AM   #10
chris_crunch
Member
 
Registered: Jan 2016
Location: Braintree, Essex
Distribution: Ubuntu 14.04
Posts: 107

Original Poster
Rep: Reputation: Disabled
I think it's working but I forgot to hit sudo. So it's saying Permission denied 1.2 million times lolol

Code:
 chris@chris-crunch:/data1/IMAGENET/training_data$ for a in *.tar; do  sudo mkdir /data1/IMAGENET/training_data/something/$a;    tar -C /data1/IMAGENET/training_data/something/$a -xf $a; done
tar: n01440764.tar: Cannot open: Permission denied
tar: n01443537.tar: Cannot open: Permission denied
tar: n01484850.tar: Cannot open: Permission denied
tar: n01491361.tar: Cannot open: Permission denied
tar: n01494475.tar: Cannot open: Permission denied
tar: n01496331.tar: Cannot open: Permission denied
tar: n01498041.tar: Cannot open: Permission denied
tar: n01514668.tar: Cannot open: Permission denied
tar: n01514859.tar: Cannot open: Permission denied
tar: n01518878.tar: Cannot open: Permission denied
tar: n01530575.tar: Cannot open: Permission denied
tar: n01531178.tar: Cannot open: Permission denied
tar: n01532829.tar: Cannot open: Permission denied
tar: n01534433.tar: Cannot open: Permission denied
tar: n01537544.tar: Cannot open: Permission denied
tar: n01558993.tar: Cannot open: Permission denied
tar: n01560419.tar: Cannot open: Permission denied
tar: n01580077.tar: Cannot open: Permission denied
tar: n01582220.tar: Cannot open: Permission denied
tar: n01592084.tar: Cannot open: Permission denied
Okay it's churning away... fingers crossed this works...

Last edited by chris_crunch; 02-23-2016 at 08:22 AM.
 
Old 02-23-2016, 08:24 AM   #11
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 15,646

Rep: Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129Reputation: 5129
in that case try to add sudo before the tar command too
or execute the whole script as root, but in that care remove sudo from inside.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening tar.gz2 files help please ixxblazexxi Mandriva 1 11-11-2007 10:58 AM
Not successful in opening *.tar.gz files Erik_the_Red Linux - Newbie 3 05-31-2005 11:04 AM
opening tar files zeviddalop Linux - Newbie 5 10-25-2004 08:27 PM
Opening/Unziping .tar.gz files java999 Linux - Software 5 09-25-2004 12:17 PM
Opening .tar.bz2 files dominique Linux - Newbie 7 11-30-2001 03:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration