LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 04-05-2021, 06:39 PM   #1
andrewysk
Member
 
Registered: Mar 2020
Posts: 797

Rep: Reputation: Disabled
Alter command to extract iso content , tar cf - . | (cd /tmp/testiso_temp; tar xfp -)


I have mounted an bootable iso image onto /mnt/testiso
Code:
$df -H
/dev/loop12      17M   17M     0 100% /mnt/testiso

$pwd
/mnt/testiso

As you can see the content of the iso. 
$ ls
boot  boot.catalog  efi.img  mach_kernel  System


$ tar cf - . | (cd /tmp/testiso_temp; tar xfp -)
this is used to extract the content of the iso to a temporary folder (/tmp/testiso_temp).

Can you please explain to me how this tar with all those options extract the content of the mounted iso to a new file for me to modify ?

I tried to understand the tar options, but just can't get it.
Code:
$ tar cf - /mnt/testiso/ | (cd /tmp/testiso_temp; tar xfp -)
when i tried to change the code as above, the output of it is weird.. instead of it extract the files to /tmp/testiso_temp, it even move the whole /mnt/testiso to /tmp/testiso_temp...
why ?

I just want to alter the code so that i can insert iso path instead of have to be in the directory itself..

Thx
Thx
 
Old 04-05-2021, 06:51 PM   #2
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,677

Rep: Reputation: Disabled
See B.1 Copying directory hierarchies in the GNU tar manual.

The first command, tar cf - /mnt/testiso/, creates a tar archive from files in /mnt/testiso/ and writes it to the standard output.

Pipe feeds that tar archive to the subshell.

In the subshell, cd changes to /tmp/testiso_temp, and tar unpacks the archive fed from the pipe.

Last edited by shruggy; 04-05-2021 at 06:53 PM.
 
1 members found this post helpful.
Old 04-05-2021, 08:06 PM   #3
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
A much simpler way to copy the files to a different location would be to use either the copy command (cp) or rsync.
Code:
cp -ar /mnt/testiso/* your/destination/directory/

or

rsync -av /mnt/testiso/* your/destination/directory/
instead of having the overhead of creating then extracting the tar file.
 
Old 04-05-2021, 08:32 PM   #4
jefro
Moderator
 
Registered: Mar 2008
Posts: 22,008

Rep: Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629
http://isgsp.net.tripod.com/rick/cmds/tar.html

Somewhat similar.
 
1 members found this post helpful.
Old 04-06-2021, 12:15 AM   #5
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,816

Rep: Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211
Code:
tar cf - /mnt/testiso/
stores /mnt/testiso/* in the tar file (that exists as a strean). GNU tar omits the leading / so it becomes mnt/testiso/*

Code:
(cd /tmp/testiso_temp; tar xfp -)
extracts the file names from the tar file (stream), e.g. with a leading mnt/iso, so the resulting file names are /tmp/testiso_temp/mnt/testiso/*

Use another cd and store the short file names!
Code:
(cd /mnt/testiso && tar cf - .) | (cd /tmp/testiso_temp && tar xfp -)
Unlike ; the && only continues with the next command if the previous command had a good exit status.
 
Old 04-06-2021, 02:35 AM   #6
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,808

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by andrewysk View Post
I have mounted an bootable iso image onto /mnt/testiso
Code:
$ tar cf - . | (cd /tmp/testiso_temp; tar xfp -)
this is used to extract the content of the iso to a temporary folder (/tmp/testiso_temp).

Can you please explain to me how this tar with all those options extract the content of the mounted iso to a new file for me to modify ?
It may be in the tar(1) manpage but it's hard to find (and, Ha!, just trying searching for "-") but the "-" used in your tar commands refers to STDIN or STDOUT depending on whether it's used in a tar create or extract operation. By using the pipe symbol you're connecting STDOUT of the process running on the left side of the pipe to STDIN of the process on the right side of the pipe. The neat trick with the parentheses is that they cause a subprocess to be created that, first, switches to the target directory and, then, invokes tar to take input from the pipe and writes its output into the target directory.

Another way to accomplish the directory tree copy operation would be to use cpio(1). See: "info cpio -> Concept Index -> copying directory structures". For your case:
Code:
# cd /mnt/testiso
# find . -depth -print0 | cpio --null -pVd /tmp/testiso_temp

HTH and have fun...
 
  


Reply



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
Extract ISO to HD, create ISO from Extractions, Boot ISO LemensTS Linux - Software 1 12-28-2010 01:10 PM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 02:53 AM
Does anyone Know how to open either .iso.rz or these .iso.xdelta,.iso.bz2,.iso.lzma?? maximalred Debian 5 06-09-2004 06:15 AM
Numerous scb_*.tmp files in /tmp dburk Programming 3 08-18-2003 04:28 PM
Newbie question - /tmp /var/tmp Mr happy Linux - Security 3 01-27-2003 01:03 PM

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

All times are GMT -5. The time now is 02:28 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