In this video, we're going to discuss
how you can acquire software
using Linux commands from the command line.
Previously, you learned about installing
a software repository as your primary method
of installing apps or acquiring software in Linux.
However, this isn't the only way to do things.
You can also download software using the command line,
or by writing a script to automate the download
and installation process for you.
Because of the open source nature of Linux software,
it is very common for you
to be able to freely download applications
directly from a website
or from your applications vendor.
In addition to this, there's many websites out there
that centralize information about available software
as well as different Linux distributions.
You can search the internet for Linux software
and come up with lots of great examples.
For example, there's programs like Audacity
to do sound editing,
GIMP to do image manipulation,
and Nmap to do network scans.
All of these are open source software
that you can download from GitHub
or the vendor's website
depending on how they like to distribute their software.
Now, most of us when we go online
and we download files,
we do this using our web browser.
So we go and use Firefox or Google Chrome,
we go over to a website like diontraining.com,
we find the link we want,
we click on it, and the file downloads.
Now, that's a great way to do things
but it's also possible to access websites
by using your command line.
And this is especially useful
when you're trying to download files
that you already know where they're located
by knowing the URL,
and that way you can script these things.
To do this, you can use
either the wget or curl commands.
These can both be used inside of a script
or inside of the Bash shell,
and that can help you automate the process
of downloading package files
or the source code itself.
For instance, if I wanted to download a file
from the Samba website using the wget command,
I could simply enter
wget http://download.samba.org/pub/samba/samba-latest.tar.gz
and this will download the tarball gunzip file
of the latest version of Samba
that I may want to install.
Now wget and curl both perform
basically the same function,
but there are some differences between them.
First, let's talk about wget.
Wget, for example, is a command line utility only,
but curl can actually be implemented
using a cross platform library known as libcurl,
and this makes it easily imported into other systems
like OS X and Windows.
Wget can also download files recursively
but curl can't do that.
And that means if it finds one file
and that's what you told it to go to,
that's the only thing it's going to download,
whereas wget can actually download things
underneath certain directories
and download all the files.
Wget supports downloading using HTTP or HTTPS
as well as FTP,
but curl can support many other network protocols.
Wget is actually better suited
for straightforward downloading of files
from a web server,
but curl is much better suited
to building and managing more complex requests
and responses from different web servers,
and so when you're making more complex things
inside of your automations and scripts,
you'll probably lean towards curl.
Now to use either of these,
it's basically the same format.
You're going to type in wget,
the options, and the URL,
or curl, the options and the URL.
Now, Linux also has two useful utilities
that can help you manage your files.
These are known as tar and gzip.
You'll notice it ended with .tar.gz.
Well, tar is actually what's known as a tar bundle.
Tar stands for tape archiver,
and a tar file actually bundles together multiple files
into a single tarball with a tar extension.
This makes it easier to download things
because I can just download one thing
that has all the files inside of it.
But, there's no real compression here
or anything like that.
The server administrator
will actually create the bundle of files
and save them as a .tar,
and then whoever downloads that bundle
will have to extract those files from it
to be able to get all the files back out.
For example, if I wanted to take every image
that's displayed inside this course
and put it in a single directory,
I can do that on my computer,
but if I wanted to give that entire directory
and all the hundreds of images to you,
that would be pretty difficult.
But if I put them in a tarball,
I can give you one file
that when you untar it on your system,
you would now have the hundred of image files inside of it.
So to do this, we would use the tar command.
Now the tar command uses the -c option
to create the tarball.
If I use the -x option, that will extract the tarball,
and if I use the -v option,
that will enable verbose mode,
if I use -r, this will append more files
to an existing tarball,
and -t will actually test the tarball
to see what files are included in the tarball.
Finally, we have -f,
which will specify the name of the tarball
in the next argument.
So for example, if I wanted to create a tarball
that contain all my images,
I can type in tar -c and then -f images.tar.
This creates an empty tarball
that will now hold all of my images.
Now if I wanted put all the images in it,
I can then do that using the append option
of tar -r and then put all those files
into the existing tarball.
Now, another thing you might want to do
is actually reduce the size of this,
because if I gave you a tarball
that contained hundreds of images,
that's going to be a really large file.
So, we're going to want to compress that,
and this will actually take one or more files
and reduce their size,
which makes downloads a lot easier
and a lot more efficient.
Now, there are lots
of different compression formats available,
but the one we're going to cover first is gzip
because you already saw it earlier
when I showed you the .tar.gz extension.
When you compress a file with gzip,
the resulting extension is going to be .gz.
And just like you saw earlier
with the Samba example I used,
it was a .tar.gz.
Why was this?
Well, because first they created a tarball
with all the files we wanted,
and then we compressed it using gzip.
Now, this compressed tarball format
is either going to be written as .tar.gz
or it can be shortened to .tgz
as its file extension.
Most file repositories,
that are going to distribute software packages
will do so in a tarball gzip format.
To use gzip and compress a file,
simply type in gzip and the file name
and the resulting file will be called file name .gz.
If you want to decompress it
because you downloaded a .gz file,
you're simply going to type in gzip -d and the file name
to decompress that file
and now it'll be back to the original format.
So once I've downloaded samba-latest.tar.gz,
I would type in gzip -d samba-latest.tar.gz
and hit Enter.
This will uncompress it,
and give me the resulting file of samba-latest.tar.
Now, if I want the files inside of that
I need to untar that tarball.
And to do that, I'm going to use tar -x samba-latest.tar
and hit Enter.
This will then ungroup that tarball
into the individual files
that are contained inside of the samba-latest tarball
that we have downloaded from the internet.
Now, there are other compression programs out there as well
but by far,
the most common you're going to see is gzip.
But let's talk about three other ones.
We have bzip2, zip, and xz.
First let's talk about bzip2.
bzip2 is a command line utility
that's used for file compression.
It can only compress a single file at a time
just like gzip.
Now, bzip2 does use a different compression algorithm
known as the Burrows-Wheeler
block sorting text compression algorithm,
and it uses Huffman as its coding mechanism.
That said, what you really need to remember
is that bzip2 is a program that you can use
to compress and decompress one single file.
To use bzip2, you're going to use it
just like you did gzip.
To compress a file using bzip2,
simply type in bzip2 -z and the name of the file
such as samba-latest.tar.
When you do this, your file extension
will show up as .tar.bz2.
To decompress this file,
simply type bzip2 -d and the file name.
The next one we have is known as zip.
Now, zip is a widely used archive file format
that supports lossless data compression.
Zip is basically a file
that contains one or more compressed files
or directories inside of it,
and this will usually have a .zip file extension.
The nice thing about zip
is that you don't have to create a tar file first,
because you can actually zip up
multiple files at once.
To zip one or more files, simply type in zip,
the archive name that you want to use,
and then a list of file names
with a space between each one.
So for example, I might use something like
zip Jason.zip Jason Dion Training.
This would take the three files,
Jason, Dion, and Training,
and place them into the zip archive, Jason.zip.
Now, if I want to get those files out of the zip file,
how do I do that?
Well, there's actually a separate command for that
called unzip.
And to use this, we're simply going to type in unzip,
and then the name of the file.
So, unzip Jason.zip will then take out
the three files I had,
in this case, Jason, Dion, and Training,
and place them into the current directory.
If I want to specify where I want them to go,
I can type in unzip, the file name, -d,
and then the path to that directory.
And that way, those files will go where I want them to
and not just the current working directory.
Now xz is the final type of compression
that we're going to talk about.
And xz was actually created
as an upgraded version of gzip, essentially.
It does all the same things that gzip will do,
and it does them pretty much with the same options.
The difference is
you're going to get a much smaller file size
as a result because it has better compression.
Now, the drawback to xz
is that it doesn't ship by default
with all Linux distributions.
So you're going to have to install it
using a package manager like YUM, DNF, or APT,
depending on the Linux distribution that you're using
if you want to use xz.
Now with xz, if you're going to use it
to compress a single file
just like you did with gzip,
it operates the exact same way.
You type in xz and the name of the file,
such as samba-latest.tar
Then, you can decompress that
by using the -d option.
So, xz -d samba-latest.tar.xz,
and this would then decompress that file
back into the .tar file.
Now, in this lesson,
I've talked a lot about tar
and the different compression formats
that you can use
such as gzip, bzip2, zip, and xz.
But it's important to note that tar
can also do some of that compression for you
when you're creating your tar bundle.
And I saved this for the end
because I wanted to make sure you understood the concept
of grouping the files together
using the tar functions,
and then compressing them using the compressor.
Now, when you're doing this,
you can specify which option you want
for which compressor you want to use.
For example, I can use tar -cfz,
and then the file name.
What is this doing?
Well, the -c creates the tarball,
f uses the file name I specified,
and -z says to use this archive
and compress it using gzip.
Now, if I wanted to use bzip2
as my compression instead,
I would use tar -cf lowercase j.
And this says to use bzip2 as my compression engine.
Now, if I wanted to use xz instead
as my compression engine,
I would use tar -cf capital J,
and this tells it I want to use xz
for that compression.
So as you can see,
tar can be used to either
gzip, bzip2, or xz compress your files
inside of that tarball.
Now notice tar cannot use zip
as a compression format
but it can use gzip, bzip2, or xz.