|
| 1 | +# Introduction to Unix (continued) |
| 2 | + |
| 3 | +In this part of the Unix tutorial, you will learn to download files, compress and decompress them, and combining commands |
| 4 | + |
| 5 | +## Download files |
| 6 | + |
| 7 | +`wget` can be used to download files from internet and store them. The following downloads and stores a file called to the current directory. |
| 8 | + |
| 9 | +`wget https://raw.githubusercontent.com/HadrienG/tutorials/master/LICENSE` |
| 10 | + |
| 11 | +will download the file that is located at the above URL on the internet, and put it **in the current directory**. This is the license under which this course is released. Open in and read it if you like! |
| 12 | + |
| 13 | +The `-O` option can be used to change the output file name. |
| 14 | + |
| 15 | +`wget -O GNU_FDL.txt https://raw.githubusercontent.com/HadrienG/tutorials/master/LICENSE` |
| 16 | + |
| 17 | +You can also use wget to download a file list using -i option and giving a text file containing file URLs. The following |
| 18 | + |
| 19 | +``` |
| 20 | +cat > download-file-list.txt |
| 21 | +url_1 |
| 22 | +url_2 |
| 23 | +url_3 |
| 24 | +url_4 |
| 25 | +[CTRL-C] (to exit cat) |
| 26 | +``` |
| 27 | + |
| 28 | +`wget -i download-file-list.txt` |
| 29 | + |
| 30 | +## Compressing and decompressing files |
| 31 | + |
| 32 | +### Compressing files with gzip |
| 33 | + |
| 34 | +gzip is a utility for compressing and decompressing individual files. To compress files, use: |
| 35 | + |
| 36 | +`gzip filename` |
| 37 | + |
| 38 | +The filename will be deleted and replaced by a compressed file called filename.gz To reverse the compression process, use: |
| 39 | + |
| 40 | +`gzip -d filename.gz` |
| 41 | + |
| 42 | +Try it on the License you just downloaded! |
| 43 | + |
| 44 | +### Tar archives |
| 45 | + |
| 46 | +Quite often, you don't want to compress just one file, but rather a bunch of them, or a directory. |
| 47 | + |
| 48 | +tar backs up entire directories and files as an archive. An archive is a file that contains other files plus information about them, such as their filename, owner, timestamps, and access permissions. tar does not perform any compression by default. |
| 49 | + |
| 50 | +To create a gzipped disk file tar archive, use |
| 51 | + |
| 52 | +`tar -czvf archivename filenames` |
| 53 | + |
| 54 | +where archivename will usually have a .tar .gz extension |
| 55 | + |
| 56 | +The c option means create, the v option means verbose (output filenames as they are archived), and option f means file. |
| 57 | + |
| 58 | +To list the contents of a gzipped tar archive, use |
| 59 | + |
| 60 | +`tar -tzvf archivename` |
| 61 | + |
| 62 | +To unpack files from a tar archive, use |
| 63 | + |
| 64 | +$ tar -xzvf archivename |
0 commit comments