Lesson 01
Basic Unix Terminal Commands (Learn the Linux bash shell)
Summary
Basic UNIX Commands Tutorial
Introduction
In this tutorial, we will cover several fundamental UNIX commands that are essential for navigating and managing files within the UNIX file system.
Commands Covered
1. Who Am I
- Command:
whoami
- Description: Displays the current username.
- Example Output:
I am NVKTutor.
2. Print Working Directory
- Command:
pwd
- Description: Shows the current directory path.
- Example Output:
/user/nvktutor
3. List Files
- Command:
ls
- Description: Lists all files and directories in the current directory.
- Note: In UNIX, everything is treated as a file.
4. Change Directory
- Command:
cd <directory>
- Description: Moves between directories.
- Example:
- To move to the Java directory:
cd Java
- To confirm the change:
pwd
(output will show you're in the Java directory) - To go back:
cd ..
- To move to the Java directory:
5. Clear Screen
- Command:
clear
- Description: Clears the terminal screen of previous commands and outputs.
6. Navigating Multiple Directories
- To go back and then to another directory in one command:
cd ..
(go back) thencd <next_directory>
.
7. Viewing File Contents
- Command:
head <file>
andtail <file>
- Description:
head
shows the first 10 lines of a file.tail
shows the last 10 lines of a file.
- Example:
head conversations
tail conversations
8. Manual Pages
- Command:
man <command>
- Description: Displays the manual for a command.
- Example:
- To learn about the
head
command:man head
- To exit the manual, press
q
.
- To learn about the
Summary
- Who Am I? -
whoami
- Current Directory: -
pwd
- List Files: -
ls
- Change Directories: -
cd <directory>
,cd ..
- Clear Screen: -
clear
- View File Content: -
head <file>
,tail <file>
- Access Manual Pages: -
man <command>
Conclusion
Practice these commands to become familiar with navigating and managing your files in UNIX. With further exploration, you can learn to customize these commands using options for more complex tasks. Thank you for watching!
Video Transcript
Learn a few basic UNIX commands. Let's get started.
So first of all, the first command I'd like to introduce you is
the Who Am I command. Who Am I?
As the name suggests,
it tells you who you are. It tells you your
username. So Who Am I?
I am NVKTutor. That's my username. Alright?
So next one is P-W-D.
Print Working Directory. That basically tells me
where I am in the UNIX file system. So right now I'm in the
User directory and
slash NVKTutor. So basically my
home directory. So in UNIX
we refer to folders as directors.
Directories. And
we have files and
directories. Files inside directories, basically.
So let's see what we have
in the current directory with the LS command.
Basically it lists all the files inside the directory.
So there it is. I have a few
files here. And just so you know, there's not
a clear distinction in UNIX between
a directory and a file. Basically everything is a file.
So maybe this file here,
Java, even though it doesn't have an extension,
it could be a directory or it could be
some kind of file, maybe a text file. Now
we have some files with explicit extensions right here.
This is a GIF file, an image. This is a
C++ source code. But
in general you don't have to have an extension in UNIX.
You can just name the file whatever you want.
Now let's take a look at
my finder window here to see what they actually are.
Okay, I've used Mac OS 10.
So that's how
the files look with
a user interface
program like finder. And you can see Java is actually a
folder here, which is also called
the directory UNIX. Alright, so let's get back.
So we learned how to list the files but how do we move around?
That's with the CD command. So let's say you want to move
to the Java folder. You say CD
Java. Okay, and now we are in Java.
As you can see here my prompt changed to Java.
This tilde here means I am in my home
directory. Now I am within, I'm in
the directory called Java within my home directory. Let's just check
with PWD where we are. As you can see
slash user slash nvk tutor slash Java.
So indeed we are in Java. Now
let's say we want to go back. So how can I go back to the previous folder?
Basically CD space dot dot.
Let's say PWD.
Yes, we are back. This is an LST list of files indeed.
So to get back to the previous folder CD
space dot dot. Now let's say
I want to go to downloads CD downloads.
This is a directory. Okay, I know it's a directory.
Now let's list the contents of this directory.
Are there any files here? Let's see. Oh, there are three files here.
This movie file here, another one,
and an image, a PNG image. Cool.
So I'm saying these because there's an explicit
extension and I really know
that they are such but in general you wouldn't know
what kind of files they were. Okay.
Now let's go back.
CD dot dot. We're back here.
PWD. LS. Great.
Now let's say you want to clear the screen.
Too many things here. I want to get rid of all these things. Just say clear.
There you are.
Nice and clean. Okay, so let's play a little bit more of CD.
So let's list the files. So let's say
I'm going to go to music.
But let's say I don't want to type.
Let's say from music I want to go back to the previous folder
and then go to back and then go to Java.
How can I do that in one single command? So essentially you say
CD dot dot that goes back to the previous folder, right?
But since the dot dot here means we are in the previous folder,
from there you can go to Java. Just say slash
Java. So CD go to the previous folder
and from there you go to Java.
PWD, indeed we are in Java. If we go back, we go back to the home
directory. See?
Now let's try it again. CD let's say
movies. PWD, work in directory,
indeed movies. Let's say I want to go to the previous directory and then go to
downloads. Previous directory dot dot slash downloads.
PWD, yes, listing. Oh there they are again.
Cool. Okay. Now I am in
downloads right now. Let's go to the UNIX folder within the home
directory. CD dot dot slash UNIX. Let's clear the screen. Clear.
Okay. Now indeed in UNIX, what are the files?
Listing. Okay we have some files here. So these files I had,
I have here essentially plain text files. I created them for the purpose of this
video. As you can see, there's a text file here.
You have an explicit extension. I don't really need to have that.
For example, for this file I didn't even say,
didn't even specify any kind of format of extension but I know it's a text
file. Now on to a new command. Let's say you want
to see, check the contents of a text file, plain text file.
So in UNIX we have two useful commands called head and tail.
So head and then the name of your file, let's say
conversations. So the head command will display the first
10 lines of a file by default. Okay. So that's the file conversations. These
are the first 10 lines. Now let's say you want to check
what's in the last 10 lines. Okay. Let's use tail.
Tail conversations. See those last 10 lines of the file.
Now let's check if that really makes sense. I'm going to open up a text editor
right here. You don't have to know how to do this.
I'm going to use vi just to check the file. See the contents here are the
contents of the file. So indeed these are the first 10 lines
here. And let's go back. Do I have that there?
Let's see. Head conversations. Hey, what's up? Nothing. Watch.
That's what we had there, right?
All right. Now let's check the last 10 lines.
Going all the way to the... Okay. Three, four.
Okay. Let's see.
When I said tail conversations, indeed. Why not? This is the last line. Okay.
So it worked. So let's clear. By default, head displays the first 10 lines
of a file, text file, and tail the last 10 lines. Okay.
Just one more last command before finalize this video.
If you're unsure how to use any of these commands,
you can always check their manual pages with the command man. So man, for example,
head. So that'll bring up the manual page for the
head command. So here's the name, the command head, what it does,
usage, the options, description, and so on. It's very useful.
To quit, just type q. Okay. Let's see. You want to learn more about the
cd command. Type man, cd to bring up the manual page
for the cd command. We see a lot of stuff here. Go down.
See a shell built in command, whatever.
Lots of options and stuff. Press q to quit. All right.
Just another one. Try a man or any command you know, like pwd.
Okay, pwd return working directory name.
A few options here, how to use, and what these options do.
Okay, the options are as follows. Okay. So it's a very useful command.
And just man, space, whatever the command name is. Okay.
Just a review. So to determine who the user is right now, who am I?
I am an NBK tutor. Where am I in the file system pwd print working
directory. I am in the next folder within the home
directory. All right. Now, what are the files here?
LS. Okay. Now let's say I want to go back to the home directory,
cd, which is the previous one cd dot dot to go to the previous
directory. Okay, I'm there. Now, say I want to go,
I'm going to Java and I'm going to go from here back to the previous directory
and then to say Python, okay, cd dot dot slash Python.
pwd yes from Python. Great. Let's go back to the home directory.
Clear the screen clear. Okay. Thank you for watching.
And I hope you can practice these commands. And the next thing to do is
get a little more complex about all these commands and add some options and so on.
So we can better,
better customize or what we want to get. Okay.
Thank you for watching.
No comments yet (loading...)
No comments yet (loading...)
Did you like the lesson? 😆👍
Consider a donation to support our work: