1

I have a Drupal 8 installation in a directory called my-D8. I want to update it to drupal 8.3.1, and I've downloaded drupal-8.3.1.tar.gz. I have both in my sites directory:

/d/sites $ ls
drupal-8.3.1.tar.gz  my-d8/

When I try to extract the archive, it puts everything in a directory called drupal-8.3.1, which I expected. However, I want all the files and subdirectories of that directory to overwrite (and add to) the existing my-d8 directory.

I tried the mv command, but in my shell, it refused to overwrite existing non-empty subdirectories.

$ mv drupal-8.3.1/* my-d8/
mv: cannot move 'drupal-8.3.1/core' to 'my-d8/core': Directory not empty
mv: cannot move 'drupal-8.3.1/modules' to 'my-d8/modules': Directory not empty
...

Googling around, I found this AskUbuntu answer, but when I tried it, it didn't quite to the trick:

$ tar -xvf  drupal-8.3.1.tar.gz --directory=my-d8  --strip-components=1
drupal-8.3.1/.csslintrc
drupal-8.3.1/.editorconfig
drupal-8.3.1/.eslintignore
... ^C

Instead of overwriting files in the repo's root, it simply put the subdirectory in the repo:

$ ls my-d8/drupal-8.3.1/
autoload.php  composer.json  composer.lock  core/  README.txt

Edit I tried dope-ghoti's answer, and upon close examination, it didn't work:

$ ls
drupal-8.3.1.tar.gz  my-D8/

$ tar -zx -f drupal-8.3.1.tar.gz -C my-D8

$ ls my-D8/drupal-8.3.1/
autoload.php  composer.json  ...

$ cd my-D8/

$ git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        drupal-8.3.1/

nothing added to commit but untracked files present (use "git add" to track)

How can I easily extract the archive files and directories into their respective places in my repository?

$ tar --version
tar (GNU tar) 1.29
  • tar -C will set the directory into which to perform the extraction operation. – DopeGhoti Apr 19 '17 at 20:33
1

From the manual:

 -C DIR
       change to directory DIR

This alters the working directory of the tar process. You can also use --strip to remove the first component of the filenames (e. g. drupal-8.3.1/) in the archive. So, you can:

tar --strip=1 -zx -f drupal-8.3.1.tar.gz -C my-d8

If your tar doesn't have --strip, it should at least have --transform:

tar --transform 's_drupal-8.3.1/__' -zx -f drupal-8.3.1.tar.gz -C my-d8
  • 1
    Right back atcha - --strip seems to be the missing link here. – DopeGhoti Apr 19 '17 at 21:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.