How do I extract files without folder structure using tar

后端 未结 5 1511
无人共我
无人共我 2021-01-30 12:11

I have a tar.gz-file with the following structure:

folder1/img.gif
folder2/img2.gif
folder3/img3.gif

I want to extract the image files without

5条回答
  •  庸人自扰
    2021-01-30 13:07

    This is almost possible with tar alone, using the --transform flag, except that there's no way to delete the left over directories as far as I can tell.

    This will flatten the entire archive:

    tar xzf images.tgz --transform='s/.*\///'
    

    The output will be

    folder1/
    folder2/
    folder3/
    img.gif
    img2.gif
    img3.gif
    

    You will then need to delete the directories with another command, unfortunately.

提交回复
热议问题