I download a tarball containing only one directory; this directory has a very long name.

I desire to change that directory's name once I extract it from the tarball but I prefer another way than `mkdir` with `strip-components 1` and `-C`. 

I consider `mv` but I prefer to automatically hold the directory's name in a variable in advance;  

I thought command substitution might help by holding output **in the form of** directory name but I can't see how it can be selective only for a name (or of any particular directory) in the tarball.

How is it possible with command substitution or if not, what alternative is possible?
['https://unix.stackexchange.com/questions/536207', 'https://unix.stackexchange.com', 'https://unix.stackexchange.com/users/-1/']
The following assumes that you are working with an archive in the current directory.

```
tar -x -f "$archivedir.tar"
mv "$archivedir" new-name

```

This assumes that the variable `$archivedir` contains the name of the `tar` archive without the `.tar` suffix and that this is also the name of the directory that will be created when extracting the archive. 

It extracts the archive and renames the created directory.

If you have the filename of the `tar` archive in `$tararchive` and if the filename suffix is `.tar` (included in the value of `$tararchive`):

```
tar -x -f "$tararchive"
mv "$(basename "$tararchive" .tar)" new-name

```

The `"$(basename "$tararchive" .tar)"` bit could be replaced by `"${tararchive%.tar}"`.
With GNU tar you can use a sed-like expression to transform the file names:

```
tar -xf archive.tar.gz --xform='s,^very_long_name,short,'

```

Read about the whole thing [here](https://www.gnu.org/software/tar/manual/tar.html#SEC115).