The fragment of manpage you included in your question comes from man
for GNU tar. GNU is a software project that prefers info manuals
over manpages. In fact, tar manpage has been added to the GNU tar
source code tree only in
2014
and it still is just a reference, not a full-blown manual with
examples. You can invoke a full info manual with info tar, it's
also available online
here. It contains
several examples of --strip-components usage, the relevant fragments
are:
--strip-components=number
Strip given number of leading components from file names before extraction.
For example, if archive `archive.tar' contained `some/file/name', then running
tar --extract --file archive.tar --strip-components=2
would extract this file to file `name'.
and:
--strip-components=number
Strip given number of leading components from file names before extraction.
For example, suppose you have archived whole `/usr' hierarchy to a tar archive named `usr.tar'. Among other files, this archive contains `usr/include/stdlib.h', which you wish to extract to the current working directory. To do so, you type:
$ tar -xf usr.tar --strip=2 usr/include/stdlib.h
The option `--strip=2' instructs tar to strip the two leading components (`usr/' and `include/') off the file name.
That said;
There are other implementations of tar out there, for example FreeBSD
tar manpage has a
different explanation of this command:
--strip-components count
Remove the specified number of leading path elements. Pathnames
with fewer elements will be silently skipped. Note that the
pathname is edited after checking inclusion/exclusion patterns
but before security checks.
In other words, you should understand a Unix path as a sequence of
elements separated by / (unless there is only one /).
Here is my own example (other examples are available in the info manual I linked to above):
Let's create a new directory structure:
mkdir -p a/b/c
Path a/b/c is composed of 3 elements: a, b, and c.
Create an empty file in this directory and put it into .tar archive:
$ touch a/b/c/FILE
$ tar -cf archive.tar a/b/c/FILE
FILE is a 4th element of a/b/c/FILE path.
List contents of archive.tar:
$ tar tf archive.tar
a/b/c/FILE
You can now extract archive.tar with --strip-components and an
argument that will tell it how many path elements you want to be removed from the a/b/c/FILE when extracted. Remove an original a directory:
rm -r a
Extract with --strip-components=1 - only a has not been recreated:
$ tar xf archive.tar --strip-components=1
$ ls -Al
total 16
-rw-r--r-- 1 ja users 10240 Mar 26 15:41 archive.tar
drwxr-xr-x 3 ja users 4096 Mar 26 15:43 b
$ tree b
b
└── c
└── FILE
1 directory, 1 file
With --strip-components=2 you see that a/b - 2 elements have not
been recreated:
$ rm -r b
$ tar xf archive.tar --strip-components=2
$ ls -Al
total 16
-rw-r--r-- 1 ja users 10240 Mar 26 15:41 archive.tar
drwxr-xr-x 2 ja users 4096 Mar 26 15:46 c
$ tree c
c
└── FILE
0 directories, 1 file
With --strip-components=3 3 elements a/b/c have not been recreated
and we got FILE in the same level directory in which we run tar:
$ rm -r c
$ tar xf archive.tar --strip-components=3
$ ls -Al
total 12
-rw-r--r-- 1 ja users 0 Mar 26 15:39 FILE
-rw-r--r-- 1 ja users 10240 Mar 26 15:41 archive.tar
-C option tells tar to change to a given directory before running a
requested operation, extracting but also archiving. In this
comment
you asked:
Asking tar to do cd: why cd? I mean to ask, why it's not just mv?
Why do you think that mv is better? To what directory would you like
to extract tar archive first:
/tmp - what if it's missing or full?
"$TMPDIR" - what if it's unset, missing or full?
current directory - what if user has no w permission, just r and
x?
what if a temporary directory, whatever it is already contained
files with the same names as in tar archive and extracting would
overwrite them?
what if a temporary directory, whatever it is didn't support Unix
filesystems and all info about ownership, executable bits etc. would
be lost?
Also notice that -C is a common change directory option in other
programs as well, Git and
make are first that come to my
mind.