In this video,
we're going to discuss some basic Bash commands
so you can start to use the shell
to perform some basic functions here.
There are several commands
that are important for accomplishing basic tasks
within the Linux operating system.
Many of these commands are going to be covered
in greater depth throughout this course
but a few will be discussed now
to provide you some basic command vocabulary
and to get you started with some more hands on practice
within the Bash shell.
It's also important to take note
that both of the commands
and the syntax are really important to get correctly
when you're typing them in.
This is going to be important
to get the proper way of entering in the command,
as well as the right options to use
so that that command's output
creates the expected outcome you're trying to achieve.
The first command I want to cover is known as echo.
The echo command repeats input
back to the user on the screen.
This is commonly used to send information to the user
when you're running a script
or a long series of commands from a given file.
For example, if I type in echo "Good morning!",
this is going to return good morning
inside of the command line interface.
The next command we have is the list command.
This is known as ls.
The ls command lists the contents of a directory
and can be given options to view their permissions,
hidden files and other information.
For example, I like to use the ls -a command
because this lists the directory's contents,
including all the hidden files.
The next one we have
is known as the present working directory.
Now the pwd command is going to display
the current working directory that you're in
while the cd command is the change directory command.
And you use this to change your current working directory
to another directory.
For example, if I typed in cd /etc,
this is going to change my current working directory
over to the /etc directory.
The next command we have is the copy command.
The copy command is written as cp.
The cp command is going to copy a file
or directory to another location.
So if you type in cp file1 file2,
this will copy the contents of file1 to file2.
Now if I wanted to make a new directory,
I can use the make directory command or mkdir.
The mkdir command will create a new directory
of the given name that I specify.
So if I type in mkdir newdir,
it's going to create a new directory called newdir.
The next command we have is the clear command.
The clear command is going to be used
to clear the command line interface of all the text
and bring you back to the top of the screen.
I think about this like a magic eraser.
It's going to clean everything off of my screen, instantly.
This is really useful when you're starting a new task
and you want to eliminate any distracting information
from your past command entries.
Another thing we want to talk about
is how we can look at text files
because Linux system configurations are usually held
within these text files.
So if you want to be able to view the contents of those files,
you need to use the cat command.
The cat command or CAT is going to be used
to view the contents of a file
without the option to edit that file.
It's basically just a way to view it.
An example of this would be typing in cat file1
and that's going to display the contents of file1
on the screen.
Now, the problem with this
is that if file1 is really long,
it's going to scroll off the screen
and you're not going to be able to see it all.
So there's another command known as less.
The less command is used to view the contents of a file
when those contents won't fit entirely on one screen.
So by using less, it's going to break the content
into output pages, one screen at a time
that you can scroll through using the CLI.
An example of using this would be less file1.
And this will break the contents of file1
into multiple pages
when its contents are going to be put on the screen
one page at a time,
so I can see it all as it goes.
Then I can press page up or page down
to scroll through the entire screen's worth of content,
one screen at a time and when I'm done,
I'll press Q to exit the less command
and go back to the command prompt.
Now, just as you need to view
the contents of the text files,
there's going to be times
where you need to edit those text files too
and this is where a text editor comes into play.
Now in Linux, there are lots of different text editors
but the three big ones are vi(m), nano and gedit.
Vi(m) is the default text editor for Linux
but it's pretty complicated to use for most people.
Another one you can use is known as nano.
It's a simple user friendly text editor,
and personally, it's the one I use myself most of the time.
Now, nano is not pre-installed
on all distributions though, like vi(m) is,
so if you don't have nano and you want to use it,
you're going to have to install it before you can use it.
We'll talk about how to install programs
in a future lesson though.
So don't worry too much about that right now.
Now another one we can use is known as gedit.
Gedit is a graphical user interface text editor.
So it's really easy to use
but it does require a desktop graphical environment.
Something like Gnome or KDE
that's installed on your Linux system
if you want to use gedit.
Now, another thing we need to talk about
is how are you going to reboot or shut down your system?
Periodically, it may become necessary
to reboot or shut down your system
and there's several different commands to accomplish this.
The most common one that's used though,
is the shutdown command.
If you type shutdown -h now,
this'll shut down the system immediately.
The -h stands for halting it with no time delay
and then it's going to halt the system
and then shut it down all the way to powered off state.
Now, if on the other hand,
you just need to reboot your system,
you can do that by typing shutdown -r now
which says shut down and reboot the system
and bring it right back up right now.
And this will just reboot the system for you,
instead of stopping it and powering it off.
Now in Linux, the user with the administration credentials
is known as our super user or our root user.
It's generally considered a really bad security practice
for you to log into the system as the super user.
So instead, you should log in
with a non-privileged account for your daily tasks,
something like a standard user account.
However, there's going to be times
where you need to be a super user
to perform some kind of administrative task.
And so we can use the substitute user or SU command.
If you use the su command,
it's going to allow you to switch your user credentials
and by using su, you can now switch your credentials
to that of the root user.
The system then, will prompt you
to enter in the root user's password
for authorization purposes
and if you get it right,
you're going to be logged in as root
and be able to perform tasks
that were previously unavailable to you
because you were only a regular user.
But now, you're the super user.
So think about this like you would on a Window system
of switching to an administrator user account
or doing a run as administrator.
Now, one of the great things about the Bash shell
is that it keeps a history file
of all the commands you've ever entered.
You can reference this file and repeat previous commands
without having to retype all of them.
And therefore, you can increase your efficiency
and your consistency of the commands you're entering.
For example, if you type the history command,
you're going to see the output
of the most recently entered commands in the list format
and you can use the up and down keys
to cycle through that command history.
When you press enter, it will reissue the desired command
from the history to the command line interface.
Another thing that Bash shell supports
is something known as tab completion.
This enables a user to type in enough of a command,
a file name, or a directory name to be unique
and then press tab to automatically fill in
the remainder of that entry.
This feature can reduce typographical errors
and really speeds up the process of entering in commands.
For example, if I type his and press tab,
that'll automatically fill in the rest of the command
and it'll become history.
This can be a great time saver
when you're working on the Linux system
or as a cybersecurity analyst in the future.