Linux QuickTip: Downloading and Un-tarring in One Step Linux QuickTip: Завантаження і ООН-дьогтю в одному кроці
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. Це могло б бути деяким вихідним кодом для ок, що не входить в дерево портежей Gentoo, деякі документи для внутрішнього корпоративного програми, або навіть щось як мирські як нова установка WordPress.
The traditional way of downloading and untarring something in the terminal would be something like this: Традиційний спосіб завантаження і розпакування то в терміналі буде щось на зразок цього:
wget Wget http://wordpress.org/latest.tar.gz http://wordpress.org/latest.tar.gz
tar xvzf latest.tar.gz latest.tar.gz TAR xvzf
rm latest.tar.gz RM latest.tar.gz
Or perhaps the more compact form: Чи, можливо, більш компактній формі:
wget Wget http://wordpress.org/latest.tar.gz http://wordpress.org/latest.tar.gz && tar xvzf latest.tar.gz && rm latest.tar.gz & & Latest.tar.gz TAR xvzf & & 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 має дозволити такого завдання має проводитися в більш "пляма" манері.
Well, thanks to a useful little command “curl”, we can actually accomplish the mess above in just one piped statement: Ну, спасибі корисно трохи команду "завиток", ми можемо здійснити Mess вище тільки в одному водопровідної заяву:
curl локон http://wordpress.org/latest.tar.gz http://wordpress.org/latest.tar.gz | tar xvz | ТДО 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. Справді, з теоретичної точки зору, керл метод може бути швидше, ніж каскадні Wget / ТАР / RM безлад з STDOUT трубопровід буде використовувати ОЗУ в якості буфера, якщо можливо, тоді Wget і смол (з 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. До речі, TAR з опцією-V (як ми використовуємо його у всіх вищенаведених прикладах) друкує кожне ім'я файлу для STDOUT як untarred кожна. This can get in the way of curl's nice, ncurses output showing download status. Це може стати на шляху вихору приємно, Ncurses вихідний Показані стані завантаження. We can silence tar by invoking it without -v thusly: Ми можемо мовчання TAR, посилаючись на його без-V константи виглядає так:
curl локон http://wordpress.org/latest.tar.gz http://wordpress.org/latest.tar.gz | tar xz | ТДО XZ
And that's all there is to it! І це все, що до неї!

Daily Email Updates Email Щоденні оновлення
You can get our how-to articles in your inbox each day for free. Ви можете отримати наші довідкові статті у Вашу поштову скриньку щодня безкоштовно. Just enter your name and email below: Просто введіть ваші ім'я та адресу електронної пошти нижче:


You can use wget instead of curl for this: Ви можете використовувати замість Wget Curl для цього:
wget Wget http://wordpress.org/latest.tar.gz http://wordpress.org/latest.tar.gz -O- | tar xz -O-| ТДО XZ
-O- means “output to standard output”. -O-означає "вихід на стандартний висновок".
True, but curl doesn't require any extra switches to pipe to stdout. Вірно, але локон не потребує будь-яких додаткових перемикачів для перенаправлення на стандартний висновок.
On the plus side (for using wget), wget is included with most *nix systems whereas it's hit-and-miss with curl. На плюсовою стороні (для використання Wget), Wget входить до складу найбільш * nix системах тоді's Hit It-як з локони.
I wrapped this into a script that I called turl: Я завернула це в сценарій, який я назвав TURL:
——— beginning of turl ———– --- Начале TURL ----
#!/bin/sh #! / BIN / Ш.
# Usage: turl <url> # Порядок використання: TURL <url>
curl “$1″ | tar xz Curl "$ 1" | ТДО XZ
——— end of turl ———– --- Кінець TURL ----
I also wrapped wget into a script that I called tget, for servers that don't have curl Я також Wget загорнуті в сценарій, який я назвав tget, для серверів, які не мають Curl
——— beginning of tget ———– --- Начале tget ----
#!/bin/sh #! / BIN / Ш.
# Usage: tget <url> # Порядок використання: tget <url>
wget “$1″ -O- | tar xz Wget "$ 1"-O-| ТДО XZ
——— end of tget ———– --- Кінець tget ----
Awesome tip… Awesome Tip ...
I like the turl script – very useful Я хотів TURL сценарію - дуже корисна
Thank you very much Велике спасибі
I know I could done this, and you really made my day! Я знаю, я міг би зробити це, і ви дійсно зробили мій день!