
linux壓縮和解壓縮
Most of the time, when I download something it’s a file archive of some kind – usually a tarball or a zip file. This could be some source code for an app that isn’t included in Gentoo’s Portage tree, some documentation for an internal corporate app, or even something as mundane as a new WordPress installation.
大多數時候,當我下載某些東西時,它是某種文件存檔-通常是tarball或zip文件。 這可能是Gentoo的Portage樹中未包含的某個應用程序的源代碼,內部公司應用程序的一些文檔,甚至可能是與新的WordPress安裝一樣平凡的東西。
The traditional way of downloading and untarring something in the terminal would be something like this:
在終端中下載和解壓縮某些內容的傳統方式如下:
wget http://wordpress.org/latest.tar.gz
wget http://wordpress.org/latest.tar.gz
tar xvzf latest.tar.gz
tar xvzf Latest.tar.gz
rm latest.tar.gz
rm Latest.tar.gz
Or perhaps the more compact form:
或者更緊湊的形式:
wget http://wordpress.org/latest.tar.gz && tar xvzf latest.tar.gz && rm latest.tar.gz
wget http://wordpress.org/latest.tar.gz && tar xvzf Latest.tar.gz && rm Latest.tar.gz
Either way is a bit clumsy. This is a very simple operation, a powerful shell like bash should allow such a task to be performed in a more “slick” manner.
兩種方法都比較笨拙。 這是一個非常簡單的操作,像bash這樣的功能強大的shell應該允許以“更流暢”的方式執行此類任務。
Well, thanks to a useful little command “curl”, we can actually accomplish the mess above in just one piped statement:
好吧,多虧了一個有用的小命令“ curl”,我們實際上可以在一個管道語句中完成上述混亂:
curl http://wordpress.org/latest.tar.gz | tar xvz
卷曲http://wordpress.org/latest.tar.gz | 焦油xvz
No temporary files to get rid of, no messing around with ampersands. In short, a highly compact, efficient command. In fact, from a theoretical standpoint, the curl method can be faster than the concatenated wget/tar/rm mess since stdout piping will use RAM as a buffer if possible, whereas wget and tar (with the -f switch) must read/write directly from a disk.
沒有要刪除的臨時文件,也沒有與“&”號混為一談。 簡而言之,是一種高度緊湊,高效的命令。 實際上,從理論上講,curl方法可能比連接的wget / tar / rm混亂更快,因為如果可能,stdout管道將使用RAM作為緩沖區,而wget和tar(使用-f開關)必須讀/寫直接從磁盤。
Incidentally, tar with the -v option (the way we’re using it in all the above examples) prints each file name to stdout as each is untarred. This can get in the way of curl’s nice, ncurses output showing download status. We can silence tar by invoking it without -v thusly:
順便說一句,帶有-v選項的tar(在以上所有示例中,我們都使用它的方式)將每個文件名打印到stdout,因為每個文件都未解壓縮。 這可能會妨礙curl的顯示,ncurses輸出顯示下載狀態。 我們可以通過不帶-v的方式調用tar來使其靜音:
curl http://wordpress.org/latest.tar.gz | tar xz
卷曲http://wordpress.org/latest.tar.gz | 焦油xz
And that’s all there is to it!
這就是全部!
翻譯自: https://www.howtogeek.com/howto/uncategorized/linux-quicktip-downloading-and-un-tarring-in-one-step/
linux壓縮和解壓縮