How to extract .tar.gz on current directory? (No subfolder)

Currently when extracting the WordPress latest.tar.gz file from shell it extracts it inside a /wordpress/ folder.

How would I get it so it just places the files in the actual current directory?

Read More

Making an automatic script, I was thinking of doing mv /wordpress/* ./*
but would that work?

Related posts

Leave a Reply

3 comments

  1. From man tar:

    --strip-components NUMBER, --strip-path NUMBER
    strip NUMBER  of    leading  components  from  file  names  before
    extraction
    
    (1) tar-1.14 uses --strip-path, tar-1.14.90+ uses --strip-compo-
    nents
    

    So first do

    tar --version
    

    then

    tar zxvf --strip-components 1 YOURTARFILE.tar.gz
    

    for version 1.14.90+, or

    tar zxvf --strip-path 1 YOURTARFILE.tar.gz
    

    for older versions.

    Alternatively, you can of course make a simple command chain:

    tar zxvf YOURTARFILE.tar.gz && mv wordpress/* . && rmdir wordpress
    
  2. In a first step gunzip the file:

    gunzip latest.tar.gz
    

    The latest.tar file remains.
    To extract that to working folder use

    tar -x --xform s/wordpress// -f latest.tar