Sample Header Ad - 728x90

Getting rid of spurious directories with tar -xzvf, while gunzipping

0 votes
1 answer
97 views
I want to trim the path of the gunzipped tarball so that some "spurious" leading directories are excluded. Let me explain with an example. I have the following directory structure, as outputted by the tree command: tree /tmp/gzip-expt /tmp/gzip-expt ├── gunzip-dir ├── gzip-dir └── repo └── src-tree ├── l1file.txt └── sub-dir └── l2file.txt 5 directories, 2 files I want to gzip up src-tree in gzip-dir so this is what I do: cd /tmp/gzip-expt/gzip-dir tar -czvf file.tar.gz /tmp/gzip-expt/repo/src-tree Subsequently I gunzip file.tar.gz in gunzip-dir so this is what I do: cd /tmp/gzip-expt/gunzip-dir tar -xzvf /tmp/gzip-expt/gzip-dir/file.tar.gz tree /tmp/gzip-expt/gunzip-dir shows the following output: /tmp/gzip-expt/gunzip-dir └── tmp └── gzip-expt └── repo └── src-tree ├── l1file.txt └── sub-dir └── l2file.txt However, I would like tree /tmp/gzip-expt/gunzip-dir to show the following output: /tmp/gzip-expt/gunzip-dir └── src-tree ├── l1file.txt └── sub-dir └── l2file.txt In other words, I don't want to see the "spurious" tmp/gzip-expt/repo part of the path.
Asked by Xin (3 rep)
Sep 13, 2021, 08:48 AM
Last activity: Sep 13, 2021, 09:17 AM