Technology TidBits

Answers to various technical questions on php programming, mysql, linux, and many more categories.
25% off Hosting at HostGator.com:
Use Code techbits25



How can I relocate files from a tar archive with extracting the files?

Last updated: 02/08/2012
When you are extracting data from a tar archive, sometimes you want to relocate the files, here's the way to do it:

# cd target_directory
# tar -xvf tarfile.tar --strip-components=1 file_path

The "strip_components" flag takes off the number of directories from the path as specified.  The "file_path" is used if you just want part of the tar archive, rather than to unpack the entire thing. 

So, if your tar archive contains files like this:

public_html/pictures/xyz.jpg

and you want to untar them into your images directory, you could do this:

# cd images
# tar -xvf ../file.tar --strip_compenents=2 public_html/pictures

This should put the image files directly into your images/ directory.
blog comments powered by Disqus
Have your own Tech-bit to contribute? Submit it here

Other questions in this category:
How can I find out what is taking up all the space on my Linux server?
How can I use 'find' to execute commands on all files found?
How do I figure out how many processors and the speeds, etc. are in my Linux box?
How can I remove DOS linebreaks (^M) from my files?
How can I mirror / backup a set of files via ncftp?
My hostname keeps reverting to localhost (or localhost.localdomain) - how can I permanently fix this?
How can I determine if iptables is blocking traffic to my site?
Why does my ftp file listing stop at 2000 files?
How can I get a list of files most recently updated / edited?
Some find examples for excluding a directory, and executing commands
Useful script to track spammers connecting to your server
How can I turn off / view my linux firewall using iptables?
How can I split a bit tar file into multiple small files?
How can I exclude some files / directories from a tar file?



Powered by KnowledgebasePublisher 1.1
Host Gator
Content provided by Roberts WebForge, Inc.