bash 解压后的文件夹重命名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2917851/
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
Folder Renaming After Tar Extraction
提问by Cerin
I have a tarball, myarchive.tar.gz. When I uncompress it using "tar -zxvf myarchive.tar.gz", it creates a folder myarchive-x980-2303-ssioo. What's the easiest way to automatically rename the extracted folder to ensure it matches the name of the archive? I've checked tar's manpage, but it doesn't seem to have an option for this.
我有一个 tarball,myarchive.tar.gz。当我使用“tar -zxvf myarchive.tar.gz”解压缩它时,它会创建一个文件夹 myarchive-x980-2303-ssioo。自动重命名提取的文件夹以确保它与存档名称匹配的最简单方法是什么?我已经检查了 tar 的联机帮助页,但它似乎没有这个选项。
回答by Jürgen H?tzel
Manually create folder, and strip components from tarball:
手动创建文件夹,并从 tarball 中剥离组件:
archive=my.tar.gz
mkdir ${archive%.tar*}
tar --extract --file=${archive} --strip-components=1 --directory=${archive%.tar*}
回答by u5089587
mkdir pretty_name && tar xf ugly_name.tar -C pretty_name --strip-components 1
mkdir 漂亮名字 && tar xf 丑陋名字.tar -C 漂亮名字 --strip-components 1
from https://unix.stackexchange.com/questions/11018/how-to-choose-directory-name-during-untarring
来自https://unix.stackexchange.com/questions/11018/how-to-choose-directory-name-during-untarring

