开发者

in shell script,how to get file name after untar the file

i am having tar file "test.tar.gz'.now i want to get the n开发者_JS百科ame "test' after untar the "test.tar.gz'. In shell script ,how to get this.


To strip an extension from a file name, use basename:

basename test.tar.gz .tar.gz

prints test

But that is just the base name of the archive. It's not always the name of any file or directory which the tar creates. The tar archive can contain any file names. If you need those, use tar tf to list the content of the archive.


Use something like:

file="test.tar.gz"
tarfilename=${file%.tar.gz}

read up about it man bash search for variable expansion.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜