How to use Bash: The basics
Learning how to use the command line, is in my opinion, a life skill, as is driving.
BASH is the Bourne Again SHell, the default command-line interpreter for most unixes
If you have to fall back on your initramfs (recovery mode for experts), you'll get bash.
So, let's jump into bash!
Most commands in bash are a verb and a noun.
What does this mean?
Commands take to form
do_something to something.
cd ~ or
mkdir foo (More on those later).
First, before beginning the class, we need to know what a filesystem is.
In Windows, you have something like
C:\Windowsaefvhba'ifvbai;['brf aosgna dhonasd fohnads h']
In Linux, you have:
bin boot desktopfs-pkgs.txt dev etc home lib lib64 lost+found mnt opt proc root rootfs-pkgs.txt run sbin srv sys tmp usr var
and each of these has subfolders.
Everything in Linux starts at the root (
To reference something in the bin directory (folder), you do
Let's break this down.
We start at the root
Then we go into
bin, and then
As you see, the Linux filesystem is very organised.
Now, onto commands!
Now, one more thing. All Linux commands have a mnemonic.
Let's start with moving between directories.
The command for this is
cd (change directory).
Let's move to the root. (
As you can see, the verb is
cd, and the noun is
Your prompt (The stuff before where you type) should change from something like this:
*****-laptop :: ~ ‹master*› »
to something like this:
*****-laptop :: / ».
This means that you have moved.
Now, some commands don't take verbs. These usually give you data.
Here's an example:
Pwd stands for
Print Working Directory, and it tells you where you are.
If you run
pwd, you get
/, meaning you are at the root.
Now, you can move places, and see where you are, but how can you see what's around you?
That's where LIst saves the day.
This is a command that has three parts:
- A verb (
- 0 or more options
- a noun
What's an option, you say?
They are passed using one hyphen.
Some need two, but that's for later.
You should see something like above
bin boot ....
Now, let's pass some options.
ls with the option
The syntax is
This will show you all hidden files.
You should see
.. be shown in your terminal.
These directories have special meanings.
. means your current location. (
pwd is the same)
.. means a directory one higher.
If you run
cd .., you are up a directory, in the root.
Creating, moving, copying, and deleting files.
Now that we can move, let's look at how to create files and do stuff with them.
To create, use
cd (With no args), and run
If you compare a
ls before and after, you'll see that
Now, I hear you ask, how can I make a directory? That's not a file!
Well, yes, it is, but ignore that.
You make a directory with
mkdir dirname (make dir)
Lets make the dir
Now, let's copy (
cp clap foo)
Let's now remove
You can do the same thing with
mv clap foo.
I'm sorry, but I'm going to have to make this multipart because so much content.