Basic Linux Navigation
Summary
TLDRIn this tutorial, Dr. Backman introduces basic terminal navigation within a Unix-like OS. He explains the significance of the command prompt, home directory, and the tilde symbol. The video covers essential commands such as 'ls' for listing, 'mkdir' for creating directories, 'cd' for changing directories, and 'nano' for file editing. Dr. Backman demonstrates file manipulation techniques like copying, moving, and deleting files, as well as creating and running a simple Python script. He also teaches how to use relative paths and the importance of recursive commands for directory operations, concluding with a directory deletion example.
Takeaways
- 💻 The terminal is a powerful tool for navigating, creating, and manipulating files and directories in Unix-like operating systems.
- 📁 The 'ls' command lists the contents of the current directory, which is crucial for understanding your current location in the file system.
- 🏠 The 'Home' directory is the default starting point in a terminal and serves as the central location for a user's files.
- 👤 The tilde symbol (~) is a shorthand for the home directory, indicating the user's base directory in the file system.
- 📂 The 'mkdir' command is used to create new directories, allowing for organized file management.
- 🔄 The 'cd' command changes the current working directory, which is essential for navigating through the file system.
- ✏️ The 'nano' text editor is a basic tool for creating and editing files within the terminal.
- 🔗 The 'cp' command copies files, allowing for the creation of duplicates or backups.
- 🔄 The 'mv' command moves or renames files, providing flexibility in file organization.
- 🗑️ The 'rm' command deletes files, used for removing unnecessary or temporary files from the system.
- 🔧 The 'rm -r' command is used to delete directories and their contents, providing a way to clear out entire folder structures.
Q & A
What is the purpose of the tilde symbol (~) in Unix-like operating systems?
-The tilde symbol (~) is shorthand for the home directory of the current user in Unix-like operating systems.
What is the command to list the contents of the current directory in the terminal?
-The command 'ls' is used to list the contents of the current directory in the terminal.
How do you create a new directory in the terminal?
-To create a new directory, you use the 'mkdir' command followed by the name of the directory you want to create.
What does the 'cd' command do in a Unix-like terminal?
-The 'cd' command is used to change the current working directory to the one specified after the command.
How can you create a file in the terminal?
-You can create a file by using a text editor like 'nano', followed by the filename you want to create.
What keyboard shortcut is used to exit the nano text editor?
-The keyboard shortcut to exit the nano text editor is Control-X.
How do you run a Python script from the terminal?
-You can run a Python script by typing 'python3' followed by the name of the Python file.
What command is used to delete a file in the terminal?
-The 'rm' command is used to delete files in the terminal.
How can you copy a file to create a new version with a different name?
-You can copy a file by using the 'cp' command, followed by the source file name and the new destination file name.
What is the purpose of the '-r' flag when using the 'cp' command to copy directories?
-The '-r' flag stands for 'recursive' and is used with the 'cp' command to copy directories along with their contents.
How do you move a file to a different directory?
-To move a file, you use the 'mv' command followed by the file's current path and the new destination path.
What is the command to delete a directory and its contents?
-The 'rm -r' command is used to delete a directory and its contents recursively.
How can you quickly navigate back to your home directory in the terminal?
-You can quickly navigate back to your home directory by simply typing 'cd' and hitting enter.
Outlines
💻 Introduction to Terminal Navigation
Dr. Backman introduces basic navigation in a Unix-like terminal, focusing on file and directory manipulation. The tutorial begins with understanding the terminal prompt, which shows the username, computer name, and current directory. The importance of knowing the current directory is emphasized, as it serves as the basis for all terminal operations. The home directory is highlighted as the default starting point for new terminals, and the tilde symbol (~) is explained as shorthand for the home directory. The video demonstrates creating a new directory using 'mkdir' and lists its contents with 'ls'. A visualization is provided to show the impact of commands on the file system.
📂 Manipulating Directories and Files
The video continues with changing directories using 'cd' and creating sub-directories for a 'cmsc181' course. The 'ls' command is used to list directory contents, and 'nano' is introduced as a terminal-based text editor for creating and editing files. The process of saving and exiting 'nano' is demonstrated, and the video shows how to run a Python program using the 'python3' command. File operations such as deleting with 'rm', copying with 'cp', and navigating back to the home directory using '..' are covered. A shortcut to return to the home directory with just 'cd' is also mentioned. The video ends with creating a copy of a directory structure for a new course, 'cmsc182', and changing file types from Python to C++.
🔄 File Renaming and Directory Deletion
The final part of the video script covers renaming files using the 'mv' command, which is demonstrated by changing 'hello.py' to 'hello.cpp'. The process of updating multiple Python files to C++ files is shown, followed by navigating back to the home directory using relative paths. The script concludes with a lesson on deleting directories using 'rm -r', which is applied to remove the 'cmsc182' directory. The video wraps up by summarizing the basic terminal commands learned, such as 'mkdir', 'ls', 'cp', 'mv', 'rm', and 'nano', and encourages viewers to apply these skills in their own file system exploration.
Mindmap
Keywords
💡Terminal
💡Prompt
💡Current Directory
💡Home Directory
💡Tilde Symbol (~)
💡ls
💡mkdir
💡cd
💡nano
💡rm
💡cp
💡mv
💡Relative Path
Highlights
Introduction to basic navigation in the terminal of a Unix-like operating system.
Explanation of the terminal prompt and its components: username, computer name, and current directory.
Importance of being aware of the current directory in terminal operations.
Description of the 'Home' directory and its significance in Unix-like systems.
Introduction to the tilde symbol (~) as shorthand for the home directory.
Demonstration of listing directory contents with the 'ls' command.
Process of creating a new directory using the 'mkdir' command.
Changing directories with the 'cd' command to set a new current working directory.
Creating sub-directories within the current working directory.
Using the 'nano' text editor to create and edit files in the terminal.
Saving and exiting the 'nano' text editor with keyboard shortcuts.
Creating a Python 'Hello World' program and running it using the Python interpreter.
Deleting a file using the 'rm' command.
Copying a file with the 'cp' command and creating a new version of a file.
Using the '..' shorthand to navigate up to the parent directory.
Copying an entire directory structure recursively with the 'cp -r' command.
Creating a 'todo' file to note changes required for transitioning from Python to C++ files.
Moving a file to a specific directory using the 'mv' command.
Renaming files by moving them to the same directory with a new name.
Deleting a directory and its contents using the 'rm -r' command.
Summary of basic terminal commands covered: 'mkdir', 'ls', 'cp', 'mv', 'rm', and 'nano'.
Transcripts
Hey, Dr. Backman here. Let's talk about basic navigation in the terminal
of a Unix-like operating system. We'll be creating and manipulating files and directories and
learning to copy, move, and delete them as well. Okay, let's go.
When starting a terminal, you'll see text displayed that we call a prompt. This prompt
largely indicates that it's just waiting for your input, but it also can display some interesting
things as well. In this case, it's displaying 3 things: 1) the username that I'm logged in as
that's backman; 2) the name of the computer that I'm connected to in this case it's called kay;
and 3) it indicates the current directory that the terminal is working from.
Being aware of your current directory is actually really important because everything that you do
in a terminal happens with respect to the current directory that you're in. It's similar to being in
Windows Explorer on Windows or the Finder in macOS where you're working through a hierarchical set of
directories and you kind of have to remember where you are in the midst of all of that.
When opening a new terminal, it's most common for your current, working directory to be your
"Home" directory. Now, there's a single home directory for each user account in the system
and it's basically where you store all of your files and your home base of operation.
These home directories exist in Windows and macOS as well but in Unix-like systems it's a
bit more central and apparent to the user. Now, there's one piece of shorthand that's
actually really important to know and that's called the tilde symbol and that's the little
squiggly line there if you haven't heard the name of it before. That's shorthand for the home
directory. So, whenever you see that tilde symbol, know that it's referring to your home directory.
When we look back to look the terminal that I'm logged into right now,
you can see that I'm logged in as user backman, on computer kay, and I'm in my home directory.
Now that we know who and where are, it's time to start playing around!
The first thing we should do is just start looking around to see what other
files or directories are here. We can do that by typing in "ls" which stands for
list and we can list the contents of the current directory. So, I'll hit enter and
Nothing. There's not a whole lot going on here. So, let's get started by making a directory.
To make a new directory you type "mkdir" which stands for make directory and then you provide
a name for the directory that you intend to create. I'm going to go with a theme of computer
science courses and name this directory after our Computer Science I course, "cmsc181". Hit enter
and it should be there. Let's check by typing "ls" to list the contents of the current directory.
There it is! We've got a directory. On the left side of the screen,
I've created a visualization that shows you the impacts of the commands that we're
running so as we create and manipulate files and directories, this visualization will be updated
so that you can see sort of what's happening with respect to the commands that we're running.
Now, let's try to move into this new directory so that we can
make it our current working directory. To change directories, you type in "cd"
and then specify the name of the directory that you want to move in to. In this case, "cmsc181"
and then we'll hit enter. And there you go. Now notice that the prompt has changed! It
shows that the directory we're currently in is "~/cmsc181". Now that's home slash cmsc181. Let's
make a few homework directories for our "cmsc181" course. So, we'll type in "mkdir" again and
specify the name of the directories. We'll call it "hw_1" for homework 1 and then "mkdir hw_2"
for homework 2. Now with two sub-directories in our working directory, if we type "ls" we
should be able to see the results. And there we go, homework 1, homework 2, both in our current,
working directory which is "cmsc181". Now I want to create a file, but I want
to do it in my homework 1 directory. So, I want to move into that homework 1 directory
which we can do by typing "cd hw_1". And now, by hitting enter, you'll see that
the prompt has updated and it shows our new current location our new working directory.
To create this new file, I'm going to use a terminal-based text editor and it's called nano.
To use it, we type "nano" and then we name the file that we'd like to edit or modify or create.
In this case, we'll create a file called "todo.txt".
Alright, this looks different. Since we're in the nano text editor, we're free to type any text we'd
like to store into this file. Since we're in a homework 1 folder for a computer science course,
let's leave a note to uh, create a hello world program in Python, the Python programming
language. Okay, that should do it. At the bottom of the screen, in Nano,
you'll see something of a menu that describes certain keyboard shortcuts that allows Nano
to take specific actions. For instance, in the bottom-left, we see this upper-carrot-x
which stands for exit. That means control-x, the keyboard sequence, control with x at the
same time. So, let's try that option to exit nano, control-x. At this point I'm being asked
if I want to save the file before exiting and I want to type "y" for yes. Now it's asking me to
confirm the name of the file I intend to write and I'm fine with "todo.txt" so I'll hit enter.
And there we go, we just saved and quit. Now, type "ls" and hit enter.
And now you see our file here displayed in white, actually, which is different than the other things
which were displayed in blue. Those other things displayed in blue were directories and then this
file here is in white. It's just a nice little differentiation that allows you to keep track
of the files and directories that exist. Alright, so, let's actually create a Hello
World file now. So, we'll do that with "nano" and we'll say "hello.py" for a Python file.
Typing print("Hello World")' ought to do the trick. I'll save and quit with control-x. Yes,
to say that I want to save this file. Enter, to confirm the name of the file. And there we go!
And to confirm that this file exists, we'll type in "ls" again. And now we see "hello.py"
and "todo.txt" both existing within our current directory. Just for fun, let's try running our
Python program by invoking the Python interpreter. We can do that by typing "python3" and then
naming the file that we created "hello.py". Hit enter, and we have our Hello World.
Well, the "todo" file isn't needed any longer so we can get rid of that. You can delete a file by
typing in "rm" and then typing in the name of the file you intend to delete. For us that will be
"todo.txt". We'll press enter and then "ls" to see that it's gone. And no more "todo" file.
Suppose that we want to make a copy of our Hello World file. Something like a Hello World 2.0.
To make a copy of a file, you type "cp". You specify the file that you want to copy "hello.py"
and then you type the destination location of the file you want to produce. In this case, let's call
if "hello_2.py". We'll hit enter, type "ls", and now you can see we have two hello world files.
Alright, I think we're done with our Computer Science 1 course now. Let's go back towards
our home directory. But how do we go back? We haven't talked about that yet. We definitely
need to type "cd" to change directories but there's a little piece of shorthand, that's
really useful for going back a directory, up a directory towards the parent. And that's, "..". So
we can type in "cd .." and then hit enter. Now notice that our prompt has changed and
the current working directory has updated "cmsc181". We've gone back, we've gone up,
one directory. Let's do it once more and get back to the home directory by typing "cd .." yet again.
And now we can see that we're in just tilde, the home directory. Here's another little tip. If you
just type in "cd" and immediately hit enter, then it'll take you directory to your home directory
no matter what your current working directory is. That's actually a really handy shortcut.
We'll, now that we've got this "cmsc181" directory structure for our Computer Science 1 course,
let's just replicate it and use it as the foundation for our Computer Science 2 course
"cmsc182". We can do this pretty easily with the copy command "cp" to copy "cmsc181" to "cmsc182"
but, there is one little bit of a difference that's required for copying directories.
And that's that immediately after typing "cp" you need to add a "-r" and this specifies that
we want to recursively copy the contents of the original directory into that new location.
SO, in this case, we can type "cp -r cmsc182" followed by "cmsc182" our destination folder. And
hit enter. Let's type "ls" to see what we've got. And there we go, a brand new "cmsc182" directory
standing right next to our "cmsc181" directory. So, one little side distinction I should make is
that our "cmsc181" course is taught in Python and our "cmsc182" course is taught in C++. So,
I should really go into our "cmsc182" folder and change all of those files from being Python files
to C++ files. I'm going to create another "todo" text file to note all of that. SO, "nano todo.txt"
and "Change all of the python files to C++ files". Alright, control-x, yes I want to save the buffer,
confirm the file name. Okay, but wait, this "todo" file doesn't really belong in my home directory,
it belongs in the homework 1 folder of my "cmsc182" directory. So, let's move it there.
To move a file, you type "mv" short for move and then specify the file you want to move "todo.txt"
in this case. And, we'd like to push it into the homework 1 folder of "cmsc182". So you'll type in
the destination you'd like it to go to which would be "cmsc182/hw_1/todo.txt". And then hit enter.
So, notice here that we typed a path to the destination point which traversed through a
couple of directories. And we did it all relative to where we currently are the current working
directory. That's actually called a relative path and we should get familiar with the notion
of using relative paths. And let's now type the path of the folder we want to get to.
So, we could type "cd cmsc182" and then "cd hw_1" but let's just do it all in one shot
with a relative path. "cd cmsc182/hw_1". Enter. We'll see that our path updated in our prompt
which is great. And now we can type "ls" to see what we've got. And here we've got the copied
Python files as well as the "todo" file. Now, to rename these Python files,
I haven't exactly talked about how to do that but we have used a command that can be used
to rename files and that's the move command (mv). Now watch this, I'll move "hello.py"
to a new location and this time I'm going to call it "hello.cpp" for our C++ file and I'll
hit enter. "ls" and now you can see that we've updated the filename just by moving it from
the current directory to the same directory but with a new filename as it's destination point.
Now let's do the same with the next file "mv hello_2.py" to "hello_2.cpp". Enter, and "ls".
Now both of our Python files have been updated to "cpp" files. Excellent
I think we're done with our "cmsc182" course now so let's go back to the home directory. We could
do this just by typing "cd" and hitting enter that cool shortcut I talked about before, or we could
type "cd .." followed by "cd .." but let's get used to the notion of relative paths again. We can
chain these things together by typing in "cd .." which would get us back to the "cmsc182" directory
but then followed by a "/.." yet again to take us to its parent directory the home directory.
If we hit enter, we'll see that the prompt has updated to just tilde, just our home directory.
We're about done here but there's one last thing that I want to show you how to do,
and that's how to delete a directory. So, let's just delete our Computer Science 2 directory,
"cmsc182". We saw before that you can type in "rm" to remove a filename deleting the file. To delete
a directory it's very similar but, just like "cp", there's one little extra piece of information
that you need and that's to specify that we want to delete the contents of the directory
recursively. So, "rm -r cmsc182" for the directory we want to delete. We'll hit enter
and now let's type "ls". All we have left is "cmsc181", the "cmsc182" directory is all gone.
Alright, we've done it. That was a great start and now you've seen a lot of the basics. We've covered
making directories with "mkdir", we talked about listing the contents of directories with "ls",
we talked about copying files with "cp", moving files with "mv", removing files deleting files
with "rm", and we event talked about editing and creating files with nano. A good start.
Now, go off and change the world! Or, at least the contents of your home directory. Have fun!
Browse More Related Video
Linux Command Line Tutorial For Beginners 2 - ls command in Linux
How to use the Command Line | Terminal Basics for Beginners
Lecture 2 - Command line environment
25 VS Code Productivity Tips and Speed Hacks
Core Java With OCJP/SCJP-java IO Package-Part 2 || File I/O
50 macOS Tips and Tricks Using Terminal (the last one is CRAZY!)
5.0 / 5 (0 votes)