bash 如何在当前目录中提取 .tar.gz?(无子文件夹)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11362273/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to extract .tar.gz on current directory? (No subfolder)
提问by Vernard
Currently when extracting the Wordpress latest.tar.gz file from shell it extracts it inside a /wordpress/folder.
目前,当从 shell 中提取 Wordpress latest.tar.gz 文件时,它会将其提取到一个/wordpress/文件夹中。
How would I get it so it just places the files in the actual current directory?
我怎样才能得到它,所以它只是将文件放在实际的当前目录中?
Making an automatic script, I was thinking of doing mv /wordpress/* ./*but would that work?
制作一个自动脚本,我正在考虑这样做,mv /wordpress/* ./*但这行得通吗?
采纳答案by Michael Besteck
In a first step gunzip the file:
在第一步 gunzip 文件中:
gunzip latest.tar.gz
The latest.tar file remains. To extract that to working folder use
最新的.tar 文件仍然存在。要将其解压缩到工作文件夹,请使用
tar -x --xform s/wordpress// -f latest.tar
回答by Alex Howansky
Use --strip-components=1in your tar extract command.
使用--strip-components=1您的焦油提取命令。
回答by Rody Oldenhuis
From man tar:
来自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
对于 1.14.90+ 版本,或
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

