Home / Operating Systems / Linux / How can I relocate files from a tar archive with extracting the files?
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.