|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Solaris The Solaris Operating System, usually known simply as Solaris, is a Unix-based operating system introduced by Sun Microsystems. The Solaris OS is now owned by Oracle. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Not really - that is the builtin behavior of tar. Try this on /var/tmp or /tmp or your home directory (be sure there is disk space beforehand) Code:
cd /tmp
mkdir junk
cd junk
tar xvf mytarball.tar
cd ..
export DEST=/real/path/to/files
find junk -type -f |
while read fname
do
bn=$(basename $fname)
mv $fname ${DEST}/${fn}
done
rm -r ./junk |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
If all the files are at the same tree depth (I mean, they all are in the same number of directories), you can use gtar with the --strip-path or --strip-components modifier. Let's assume, your files pathnames are like these: Code:
a/b/x a/b/y a/b/z a/c/1 a/c/2 a/c/3 you can do Code:
gtar xvf archive.tar --strip-components=2 and then you get all six files in the current directory. If the tree depth is variable, I am not aware of any tar option you could use to extract the files the way you want. |
|
#4
|
|||
|
|||
|
--strip-components is not a Solaris tar option, it is for gnu tar. You can get gtar at Blastwave.org - An OpenSolaris Community Site You have to setup pkgutil first, then Code:
pkgutil -yi gtar |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
GNU tar has the option --transform , but I don't fully understand how it works. May be something like this: Code:
tar --transform 's#.*/\([^/]*\)$#\1#' -xvf <filename> |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
Quote:
Quote:
---------- Post updated at 14:03 ---------- Previous update was at 13:56 ---------- Quote:
Code:
gtar --transform 's/.*\///' -xvf <filename> Unfortunately, the directories in the tar file get restored this way too. |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Thanks for all of the replies.
Perhaps this problem can be approached from a different angle. Is there a way to use the cp command on solaris to take all of the files in the directories, and to copy them all to one directory? |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| creating separate directories according to file extension and keeping file in different directory as | Deekay.p | UNIX for Dummies Questions & Answers | 2 | 07-28-2010 10:00 AM |
| Copying a files from a filter list and creating their associated parent directories | hunter55 | Shell Programming and Scripting | 4 | 05-05-2010 04:22 PM |
| help needed with creating challenging bash script with creating directories | I-1 | Shell Programming and Scripting | 7 | 04-29-2009 05:33 AM |
| Bash and Awk for creating directories and moving files | Kiint | Shell Programming and Scripting | 11 | 07-24-2008 10:30 PM |
| extract tar files without creating directory | here2learn | UNIX for Dummies Questions & Answers | 4 | 10-02-2006 07:42 PM |
|
|