Stripping Paths from Files in Tar Archives
There is no way to get tar to ignore directory paths of files that it is archiving. So, for example, if you have a large number of files scattered about in subdirectories, there is no way to tell tar to archive all the files while ignoring their subdirectories, such that when unpacking the archive you extract all the files to the same location. You can, however, tell tar to strip a fixed number of elements from the full (relative) path to the file when extracting using the "--strip-components" option. For example:
tar --strip-components=2 -xvf archive.tar.gz
-t" ("--show-transformed option:
tar --strip-components=2 -t --show-transformed -f archive.tar.gz
The "--strip-components" approach only works if all the files that you are extracting are the same relative depth. Files that are "shallower" will not be extracted, while files that are deeper will still be extracted to sub-directories. The only clean solution to this that I can think of would be to extract all the files to a temporary location and then move all the files to single directory:
mkdir /tmp/work cd /tmp/work tar -xvzf /path/to/archive.tar.gz mkdir collected find . -type f -exec mv {} collected/ \;
feed
Comments
0 comments postedPost new comment