Skip to main content

Understanding --strip-components -C [Resolved]

This answer includes this code:

tar xvzf mediawiki-1.33.0.tar.gz --exclude-from=exclude.me --strip-components 1 -C /path/to/your/wiki

From man tar:

--strip-components=NUMBER
strip NUMBER leading components from file names on extraction

-C, --directory DIR
change to directory DIR

I didn't understand the explanation for strip components but for -C I understand like "put stripped components in noted directory and override if needed.
How do you understand these?


Question Credit: JohnDoea
Question Reference
Asked August 18, 2019
Tags: tar
Posted Under: Unix Linux
39 views
1 Answers

The --strip-components option is for modifying the filenames of extracted files. --strip-components <N> means "remove the first <N> components of the filename", where "components" is referring to parts of the path separated by /.

If you have a filename foo/bar/baz, then with --strip-components 1 the extracted file would be named bar/baz.


The -C option just means "change directory". If you use -C /some/other/place you are effectively asking tar to cd /some/other/place before extracting files. This generally means that files would be extracted relative to /some/other/place.


credit: larsks
Answered August 18, 2019
Your Answer
D:\Adnan\Candoerz\CandoProject\vQA