The first thing you'll need to learn is how to interact with
machines without a fancy graphical interface, so let's explore a
popular shell program called Bash.
Before we type any commands, let's explore a Bash shell
prompt many systems use by default.
It shows our current username, which is ec2‑user,
followed by the hostname of the device to which we are connected.
Then, it shows the name of the directory we are currently in,
which is Globomantics.
It would be useful to learn more about where we
currently are in the directory hierarchy.
The command pwd, or print working directory, is a good starting point. In
Linux, forward slashes are used to identify directories with forward slash
by itself representing the root directory.
Now that we know where we are, let's see what files are in this directory.
We can use ls, short for list, to reveal the contents.
We see two files named file1.txt and file2.txt.
Perhaps we want to get more details about these files.
Linux has a built‑in manual page for almost every command, and we can
use man ls to check the docs for ls. From here, we can scroll up and
down to read the details and use q to quit.
Specifically, we want to learn about the ‑l option, which is the long format.
This verbose output will reveal additional information about each file.
These codes on the left represent file types and permissions,
which is a complex topic we won't be digging into today.
The next two columns show the file's owner and also the
group to which the file is associated.
If multiple users need to access a file, you could apply group permissions.
Next, we have the file size in bytes, and both of these are small files.
Here is the last modified time, effectively showing when the file's contents
were last updated. Last, we have the file names from earlier.
Let's create a directory for these files.
We use the mkdir command to make a new directory.
Okay,
we created a new directory, and notice it has a little d as the first character
in the detailed ls output. To navigate into this directory,
we can use the cd command to change directories.
We can use pwd again to check our location, and notice our shell prompt changed.
Going forward is easy, but what about backward? If we use ls ‑a,
which reveals all hidden files, we'll get a clue.
In Linux, everything looks and feels like a file, even directories,
hardware components, and running processes.
The dot directory represents the current directory,
and this becomes handy when running shell scripts,
a topic covered in a future clip.
The dot dot directory represents the directory one level up,
so if we cd into the dot dot directory, it should take us back one level.
Okay, now we are back where we started.
Let's move our files into the new directory.
We can use the mv command to accomplish this,
supplying the source file first and the target directory second. We can
use ls to list the contents of the directory from here, even if we aren't
in the directory. Let's move file2 in next,
but also change its name in the process.
The mv command is also used in Linux to change file names.
Okay, I changed back into the directory, used ls, and everything looks good.
We can also copy files using the cp command.
It works like mv except keeps the source file intact.
I'll copy file1.txt to a file named coffee.txt.
Now we have three files, and notice that file1.txt and
coffee.txt have the same file size as expected.
We can use the cat command,
which means concatenate, to print the file's contents.
You can also use tab completion to reduce typing.
Let's check the other one too, keeping in mind we can specify
multiple files and cat will concatenate their outputs.
The first three lines are from our coffee file,
as we saw earlier, and now we have four new lines from our mybash file.
If you are brand new to Linux and want to edit files, I
suggest the nano editor, It's simple to use,
and I'll demonstrate a quick change.
You navigate with arrow keys and just make edits as needed.
When done,
use Ctrl+X, then y for yes to save the changes. We see the changes
along with a new file size and modification time.
I personally use Vim throughout this course,
a more advanced text editor,
and you can learn more about that using existing Pluralsight courses.
Let's remove these silly files now using the rm command.
Okay, the file is gone now,
and we confirmed with ls. We can use the ‑i option for an
interactive removal, using y to confirm.
Okay, no files left after deleting everything.
Next,
I'll move up a directory and delete the directory we were
sitting in using the rmdir command.
This is a safe way to remove directories.
Next, let's talk about environment variables.
These are dynamic variables that can be specific to your shell
process or globally accessible on a system.
They are used to describe the environment and modify
the runtime behavior of applications.
As I'll demonstrate in a future course,
you can store secrets here for easy access. To see the current
environment variables, use env. It could be a long list,
and many of these are system defaults and things you likely won't mess with.
Let's add a new one, maybe we can store a secret password so one of
our apps can access it instead of prompting us for our password every
time we run it. We use the export keyword,
followed by a variable name and equal sign and a value.
It is conventional, but not required, to use capital
letters for environment variables.
We can use env to ensure it was added.
We can access the value using the echo command, which just prints to the
console and dereferencing our variable using a dollar sign. We can
delete the variable using the unset command,
followed by the variable name.
If we try to access it, we get no output.
For an example of a well‑known environment variable,
let's examine the shell path.
This is a colon‑delimited list of locations to look for
binaries, such as ls, cd, and mv. The shell searches each
directory to find a given command,
and we can export a new path variable if we want to
modify where our executables are stored.
Last, you should understand package management.
When you want to install, update or remove software packages,
you can use the built‑in OS package manager. On Red Hat‑based distributions,
this is yum, and on Debian‑based distributions, this is apt.
You'll need to run most of these commands as root,
which is the superuser on Linux systems and can do anything.
Prefixing a command with the word sudo, also pronounced sue‑do,
allows a user to run commands as root, provided they are authorized to do so.
I'll install a package called tree that we'll use later in the course. Using
the which command, can see where the binary was installed,
which verifies that our shell path can find it. That wraps up our intro to Bash,
and you'll see me introduce new commands and techniques
through this course and several future ones.
I'll be sure to explain what I'm doing as we move along, so don't worry. Next, let's talk about software development.