Search code examples
unixarchivetar

How do I untar a file skipping the beginning of the directory structure


I created tar archives with an absolute path to save the files.

/home/mydir/dir1/dir2/dir3/file1.dat
/home/mydir/dir1/dir2/dir3/file2.dat
/home/mydir/dir1/dir2/dir3/file3.dat

I would like to untar these archives skipping the beginning of the directory structure /home/mydir/dir1. My files should be restored in any directory with this structure :

dir2/dir3/file1.dat
dir2/dir3/file2.dat
dir2/dir3/file3.dat

How can I do this with the tar command or another way ?


Solution

  • tar -xf /for/untar/your/filename.extension --strip=3 path/to/which/you/wish/to/extract