Untar specific directory and strip leading directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Untar specific directory and strip leading directories
# 1  
Old 02-21-2011
Untar specific directory and strip leading directories

Ok so I know the title was probably confusing so here goes: I have a tarball (gzipped) that has a nested directory structure . For example:

Code:
 my.tar.gz (contents)
           [.]
             ---[var]
             ---[var]---[foo]
             ---[var]---[foo]---[bar]
             ---[var]---[foo]---[bar]---[dir]
             ---[var]---[foo]---[bar]---[dir]---[thats]
             ---[var]---[foo]---[bar]---[dir]---[thats]---[nested]

What I'm having the hardest time doing is extracting the directory [dir]--[thats]---[nested] ONLY. So no /var/foo/bar before it, just that directory and it's subdirectories. Real world dir/thats/nested/ is about 6 levels down. I'm restoring from the tarball and /dir/thats/nested is the actual directory on my box. So when i extract from it, i want it to overwrite /dir/thats/nested ON MY BOX. Kinda frustrated...I'll accept any good working solution for this at this point. Basically trying to not have to copy the tarball to the / directory to get it to overwrite /dir/thats/nested.
# 2  
Old 02-21-2011
If you have gnu tar you can use --strip=3 to remove the /var/foo/bar.

Good to also use --show-transformed if you're using the -v option to list what's being extracted.
This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 02-21-2011
There's a reason you're listed in the credits of my script lol
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Untar to a particular directory is Failing

Below are my system and tar details. bash-3.2$ uname -a SunOS mymac 5.10 Generic_150400-40 sun4v sparc sun4v bash-3.2$ which tar /usr/bin/tar I use this command to untar at the file at this location: /web/applications/configurations tar -xvf bent.tar -C... (18 Replies)
Discussion started by: mohtashims
18 Replies

2. Shell Programming and Scripting

Remove directories when specific file is in directory?

Hello :) I need little help i have following cmd: this only able to delete files but not folder which contain that file find /home/test/* -name "*.testfile" -type f -exec rm -i {} \; how to delete whole directory if file called somethingblahblah.testfile is there? Thanks you :) (3 Replies)
Discussion started by: ZerO13
3 Replies

3. Shell Programming and Scripting

How to delete all the files and folders inside all the directories except some specific directory?

hi, i have a requirement to delete all the files from all the directories except some specific directories like archive and log. for example: there are following directories such as A B C D Archive E Log F which contains some sub directories and files. The requirement is to delete all the... (7 Replies)
Discussion started by: Little
7 Replies

4. UNIX for Dummies Questions & Answers

Removing directory with leading hyphen from root directory

I know that this basic question has been asked many times and solutions all over the internet, but none of the are working for me. I have a directory in the root directory, named "-p". # ls -l / total 198 <snip> drwxr-xr-x 4 root root 4096 Dec 3 14:18 opt drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: edstevens
2 Replies

5. Shell Programming and Scripting

Strip leading and numbers from a string.

Hello I have two vars loaded with $VAR1="ISOMETHING103" $VAR2="COTHERTHING04" I need to: 1) Strip the first char. Could be sed 's/^.//' 2) The number has it's rules. If it has "hundreds", it needs to be striped. If it is just two digits it shouldn't. So, for VAR1 output should be... (7 Replies)
Discussion started by: tristezo2k
7 Replies

6. Shell Programming and Scripting

Find specific files only in current directory...not sub directories AIX

Hi, I have to find specific files only in the current directory...not in the sub directories. But when I use Find command ... it searches all the files in the current directory as well as in the subdirectories. I am using AIX-UNIX machine.Please help.. I am using the below command. And i am... (2 Replies)
Discussion started by: aakishore
2 Replies

7. Shell Programming and Scripting

How to strip off the leading filename from 'wc -l' command

Hi... can anyone please tell how do i strip off the leading filename from the wc -l command.... when i fire command wc -l new1 ... its giving output as 14 new1 i want the output as just '14'... i need to use this value in the calculations in the later part of the script..... (2 Replies)
Discussion started by: swap21783
2 Replies

8. UNIX for Dummies Questions & Answers

How can you UnTar files to a different directory?

Suppose you have a TAR file created with a different directory structure and you need to UnTar (or explode) the files to a different directory structure. How can this be done? If TAR command cannot do this, are there any other alternatives (any other command) available to UnTar a .Tar file? ... (1 Reply)
Discussion started by: joshivaibhav
1 Replies

9. Shell Programming and Scripting

unTar a specific file from remote

During tar, the command used is tar cvf - * | remsh system_name dd of=/dev/rmt/0m bs=10k To untar all, we used remsh system_name "dd if=/dev/rmt/0m ibs=10k" | tar xvf - Question? How to untar a specific file from remote? Thanks alot... (2 Replies)
Discussion started by: gelbvonn
2 Replies

10. Shell Programming and Scripting

Strip leading and trailing spaces only in a shell variable with embedded spaces

I am trying to strip all leading and trailing spaces of a shell variable using either awk or sed or any other utility, however unscuccessful and need your help. echo $SH_VAR | command_line Syntax. The SH_VAR contains embedded spaces which needs to be preserved. I need only for the leading and... (6 Replies)
Discussion started by: jerardfjay
6 Replies
Login or Register to Ask a Question