Lecture 2 - Command line environment
Summary
TLDRThis session introduces the command line environment, emphasizing its importance for fully leveraging Linux's capabilities and automating tasks through scripting. It covers various terminal emulators like Terminal, xterm, Guake, and Console, and explains basic commands such as pwd, ls, ps, and uname. The presenter also delves into the Linux file system hierarchy, explaining the purpose of directories like /bin, /boot, /dev, and /etc, and how understanding this structure aids in navigating and managing files securely and efficiently.
Takeaways
- 💻 **Command Line Power**: The command line allows users to fully leverage Linux's capabilities and automate tasks through scripting.
- 🔧 **Customization and Flexibility**: Terminal emulators like 'terminal' on Ubuntu offer customization options, while others like 'xterm' are more basic.
- 🔑 **Accessibility and Activation**: 'Guake' is a unique terminal emulator that can be activated and deactivated with a keyboard shortcut, providing quick access.
- 📍 **Navigating the Environment**: The 'pwd' command is essential for identifying the present working directory, typically the user's home directory upon login.
- 📁 **Listing and Locating Files**: 'ls' is used to list directory contents, with options like '-a' to reveal hidden files and '-l' for detailed listings.
- 🛠️ **Shell Interaction**: 'ps' helps identify running processes, often revealing the shell being used, such as 'bash', and 'uname' to check the operating system.
- 🗑️ **Screen Management**: Commands like 'clear' or 'Ctrl+L' are used to clear the terminal screen for better readability.
- ⏏️ **Exiting the Shell**: 'exit' or 'Ctrl+D' can be used to exit the shell, ending the session.
- 📚 **Manual Pages**: 'man' provides access to manual pages for command help, with options to specify sections for more detailed information.
- 🗃️ **File System Hierarchy**: Understanding the Linux file system hierarchy is crucial for navigating and managing files and directories effectively.
Q & A
Why is learning about the command line environment important?
-Learning about the command line environment is important because it allows users to utilize Linux to its fullest extent, combine commands to form scripts, and automate tasks within the Linux environment.
What are some terminal emulators mentioned in the script?
-The script mentions several terminal emulators including Terminal on Ubuntu, xterm, guake, and console, which is available for the KDE environment.
How can one clear the screen in the command line environment?
-One can clear the screen in the command line environment by typing the command 'clear' or pressing 'Control + L'.
What does the 'pwd' command do in the command line?
-The 'pwd' command stands for 'print working directory' and it shows the present working directory, which is the directory where the user is currently located.
What is the purpose of the 'ls' command?
-The 'ls' command is used to list the names of all the folders or files that are in the current directory.
How can you check the processes running in the shell?
-You can check the processes running in the shell by using the 'ps' command, which lists the currently running processes.
What does the 'uname' command display?
-The 'uname' command displays the name of the operating system that is currently being used.
How can you exit the shell in the command line?
-You can exit the shell by typing the 'exit' command or by pressing 'Control + D'.
What is the significance of the command prompt in the command line?
-The command prompt is significant as it indicates that the shell is ready to accept commands. It typically shows the user's current location in the file system hierarchy.
What does the 'ls -a' command display and why is it useful?
-The 'ls -a' command displays all files in the current directory, including hidden files that start with a dot (.). It is useful for viewing files that are typically not shown by default.
What is the file system hierarchy standard mentioned in the script?
-The file system hierarchy standard mentioned is version 3.0, which is followed by all Linux operating systems, providing a consistent structure for file and directory organization.
Outlines
💻 Introduction to Command Line Environment
The speaker introduces the command line environment, emphasizing its importance for fully utilizing Linux. They highlight the ability to combine commands into scripts for automation. The video showcases various terminal emulators, such as the Terminal app on Ubuntu, xter, guake, and console, each with different customization features. The speaker demonstrates how to use the command prompt, clear the screen, and navigate the file system using commands like 'pwd', 'ls', and 'uname'. The session aims to help users understand the command line as a tool for both instruction and automation.
🔍 Exploring Basic Commands and Shell Interaction
This section reviews the commands covered in the session, such as 'pwd' for the present working directory, 'ls' for listing files, 'ps' for viewing processes, and 'uname' for the operating system. The speaker explains how to clear the screen and exit the shell using 'clear', 'control L', 'exit', and 'control D'. They delve into the anatomy of a command prompt, discussing how it can be configured and the significance of each element. The paragraph concludes with a detailed look at the 'ls' command and its options, including 'ls -a' for all files and 'ls -l' for long format listings, and introduces the concept of manual pages for command help.
🗂️ Understanding the Linux File System Hierarchy
The speaker explains the importance of understanding the Linux file system hierarchy, which is standardized across all Linux variants. They discuss the purpose of the file system hierarchy, such as locating commands and library files, and how it aids in program development and debugging. The video provides a basic overview of the file system structure, starting from the root directory and explaining the significance of special files like '.' and '..'. The speaker demonstrates how to navigate the file system using 'cd' and explores various directories and their purposes, such as 'bin', 'boot', 'dev', 'etc', 'lib', 'media', 'mnt', 'opt', 'run', 'sbin', 'srv', 'tmp', 'user', and 'var'.
📁 Navigating Directories and Understanding File Types
This segment focuses on navigating the Linux file system and understanding the organization of directories as per the file system hierarchy standard. The speaker discusses the role of directories like 'bin', 'boot', 'dev', 'etc', 'lib', and 'media', explaining their contents and purposes. They also touch upon the difference between symbolic links and actual directories, as well as the distinction between character and block devices. The video illustrates how to use 'ls -l' to view file details and how to interpret the output, including recognizing directories, links, and device files.
🛠️ Deep Dive into System Directories and Their Functions
The speaker provides a detailed exploration of system directories, their functions, and the rationale behind their organization. They discuss the contents of 'etc', 'var', 'dev', 'lib', and other directories, explaining the types of files found in each and their significance in the system. The video also covers the concepts of shareable and non-shareable directories, static and variable file systems, and the logic behind the Linux file system hierarchy. The speaker encourages users to explore the command line environment to become familiar with the file system and locate files efficiently.
🔚 Wrapping Up and Encouraging Exploration
In the concluding part, the speaker summarizes the key points discussed in the video, including the file system hierarchy and the importance of understanding it for efficient navigation and file management. They reiterate the purpose of various directories and the types of files they contain, emphasizing the need for users to explore and familiarize themselves with the command line environment. The speaker encourages further exploration and practice to gain comfort and proficiency in using the Linux file system.
Mindmap
Keywords
💡Command Line Environment
💡Script
💡Terminal Emulator
💡Command Prompt
💡Shell
💡File System Hierarchy
💡Home Directory
💡Symbolic Link
💡Device Files
💡Configuration Files
Highlights
Command line environment is essential for utilizing Linux to its fullest extent.
Combining commands into scripts allows for task automation in the Linux environment.
Terminal emulators like 'terminal' on Ubuntu provide flexibility in customization.
Guake is a terminal emulator that can be activated and deactivated with the F12 key.
The command prompt is the interface for typing commands into the shell.
The 'pwd' command shows the present working directory in the file system.
The 'ls' command lists the contents of the current directory.
The 'ps' command lists the processes running in the current shell.
The 'uname' command displays the operating system in use.
The 'clear' command or CTRL+L can be used to clear the terminal screen.
The 'exit' command or CTRL+D can be used to exit the shell.
The anatomy of a command includes the command prompt, user name, host name, and current path.
The 'ls -a' option lists all files, including hidden ones.
The 'ls -l' option displays files in long format, showing more detailed information.
The 'man' command provides access to manual pages for command help.
The file system hierarchy standard (FHS) is followed by all Linux distributions for consistency.
Understanding the file system hierarchy is crucial for navigating and managing files in Linux.
The root directory ('/') is the starting point of the file system hierarchy.
The 'cd' command is used to change directories, navigating the file system hierarchy.
Special directories like '/bin', '/boot', and '/dev' have specific roles as defined by FHS.
The '/media' directory is for removable devices, and '/tmp' is for temporary files.
The '/home' directory contains user-specific data and is the default location after login.
The '/etc' and '/var' directories contain configuration and variable data, respectively.
Exploring the file system hierarchy helps in locating files needed for program execution and development.
The file system hierarchy is designed to be shareable and static or variable as needed.
The command line environment empowers users to efficiently manage and utilize the Linux operating system.
Transcripts
Welcome to the introductory session on command line environment.
Why would we want to learn about command line environment?
Because when we are able to type out commands then we are capable of using Linux to its
fullest extent.
We can combine these commands to form a script and then we can use these scripts to be launched
at specific times and thereby automate some of the tasks that we would like to do using
the Linux environmentt.
So, the command line environmentt should be seen as not only a way by which you type out
instructions to the computer but also as a path towards automation.
On the screen you are noticing there are two apps that are giving you the command line
environment.
My favorite would be the app called terminal on Ubuntu genome environment it has flexibility
to control the font size the colours etcetera.
It also can open multiple tabs as I am showing you here.
There is another terminal emulator called xter which is here you can see and it does
not have many of those features to customize the appearance.
And a third terminal emulator would be ~~quick~~ guake which we activate by pressing the key
F12 and by pressing it again we can actually deactivate.
Once you install it and run it once then it would be in the background listening to your
command and you can open it or close it at your wish.
There is another terminal emulator called console which is available for the KDE environment
on Ubuntu as well as other Linux variant.
For most of the session we will actually look at the terminal app which is acting as a terminal
emulator for us.
Let me maximize the window so that we can see the commands clearly.
Now what you are seeing on the screen here is called the command prompt.
So, if you just keep pressing the enter key then you will see that the shell is asking
you for some input and it is prompting you for that by showing this string and this string
is called as the command prompt.
And you can actually know clear the screen by typing the command clear and the cursor
will be taken to the top of the window.
Now one of the first things that we must do when we open a command line environment is
to check where are we with respect to the files system, pwd is a command to show you
the present working director and normally you will see that you are in the home directory.
When you first login and open the thermal environment you will be placed in the home
directory of that particular user you are logged into.
In this case the home directory slash home slash user name which is what is configured
for this particular account.
The next thing that we normally do is to type ls which is to list the names of all the folders
or files that are in this current directory.
And you would see that there are certain folders available as part of the genome environment
desktop documents downloads pictures videos etcetera.
And you want to know what shell is actually responding to our commands, you may want to
list the processes that are running right now and you would notice that there is a bash
that is running.
So, our shell that we are interacting with using this terminal emulator is bash shell.
There are many other shells that we will come to that in a moment and what operating system
are we using that you could actually know by typing the command uname and let us say
we run many such commands and we would like to clear the screen we could type the command
clear and press enter and the entire display will be clear.
You could also for example type a command and the press control l to also clear the
screen and after you have played around a bit you want to exit what you would do is
type the command exit to come out of the shell.
Alternatively you can also press control d.
So, I can now press control d and come out of the shell we have an extent that is running
in the background we would like to come out of that.
So, we would type exit and then come out of that.
And when I press F12 I am opening the ~~quack~~ guake terminal and you could of course you
can exit from that also but when you press F12 again another shell is actually shown
to you.
And I can run the same commands there and get the same output irrespective of the shell
or the terminal emulator the commands that you are sending are being responded from the
operating system.
Now let us suggest to wrap up what we have discussed till now.
So, what have we been doing now.
So, what we did was we opened a terminal emulator and most of the things we did was on terminal
app and we ran some commands pwd present working directory ~~tells~~, ls to list the folders
are files in the directory, ps to look at the processes that are running in that particular
shell, uname to look at what is the operating system, that is actually responding.
So, these are the some of the commands that we started off and if you were able to clear
the screen by pressing control L and also come out of the shell by pressing control
D.
Now if you look at what we have been doing there is command prompt that is there and
then there is a command that we have written.
So, let us look at the anatomy of the spiritual command.
So, you see that when we write a command the command prompt in front of the command has
many portions which can be configured separately we will discuss about that when we come to
the variable called ps1.
For now you see that the command prompt has the user name and then an ~~ad~~ at symbol
after that the name of the machine followed by a colon and then the path where the command
is being executed and then a dollar to signal that from then onwards you can actually start
typing and the comment that we typed is ls and sometimes for some of the commands we
need to give some options and here is an example ls -a.
So, let us look at how this comment would look like.
Now let us look at these commands a little more in detail.
So, we have type command ls to look at what all the files that are in the current directory.
We can actually now give an option to that command, I would give an option -a.
So, most of the Linux options would have hyphen or a minus sign in front of them and you would
see that there are a lot more files are being displayed.
So, by this -a option will list files which also have dot in front of them which means
that those are basically hidden from the user for routine operation.
So, if you press ls you would see the files that are used by the user in a routine manner
and -a if you give as an option then ls would give you the hidden files also which are having
a dot in the first possession of the name.
And if you press ls -l the list of files is displayed in a different manner this is called
the ~~long~~ long format and we will discuss these fields in detail in a moment.
You can get help on any command in the Linux thanks to the manual pages that come bundled
along with the operating system.
And you can pass on any command name as an argument to the command man and then get help
on it.
So, let us ask for a manual page on the command ls and you can see the help for the ls command
you can read this to expand the scope of how the ls command would work for you.
The most frequent options that are used with ls are ls -a to list all the files and ls
-l to list the files in a long format.
So, here is what we have done we have run the command man with the argument ls.
So, that we are looking at the manual page for the ls command to understand various options
that can go along with the ls command.
Now the manual pages come in many sections and this is just a textbook information to
let you know that the manual pages cover various aspects of the operating system and the section
one is where the shell commands are being described.
So, you can actually ask man pages to be displayed in the section one for the command ls.
So, here what happens is that when you type man space 1 space ls, 1 becomes an option
and ls becomes an argument.
Let us explore the file system of a Linux operator system.
Luckily for us the file system hierarchy standard version 3.0 is what is followed by all the
Linux opening systems irrespective of the variant that we are using.
So, we are using the Ubuntu 20.04 lts version and you could shift to another version of
Linux and you would see that the folders will have the same name and they will be located
in the same hierarchy as we will be exploring shortly.
Why do we need to understand how the file system hierarchy is?
The reason is that when we log to the system and when we open a command line environment
in a shell we are placed at a particular location in the hierarchy namely our home directory
and we have permissions to create files in that directory and perhaps also in some other
directory such as slash temp but we do have read access to many files that are there in
several folders and we should be able to traverse the hierarchy.
And locate commands corresponding to specific applications that we would like to run and
very often we need to identify the right location of a library file because it is required for
some compilation of a program.
The files corresponding to libraries are header files to compile our codes and the ability
to traverse the file system hierarchy will actually determine how soon we are able to
debug our difficulties with respect to compilation requirement and get on with the program development.
So, it is very useful to familiarize ourselves with file system hierarchy of Linux.
So, here is a sample of the file system hierarchy the forward slash or slash simply is the root
directory and that is a starting point for the file system hierarchy.
This character forward slash is also used as a field separator to indicate the path
to any directory.
As we see now let us say for example we want to refer to this directory called bin which
is under directly called user then you would write that part for this bin as slash user
slash bin.
And you would see that there are a number of directories with specific names which will
actually have their meaning as described in the file system hierarchy standard 3.0.
The user directory is here the home directory for a user and under the home directory there
are folders which are created by the operating system while creating that account and there
are also folders that the user can create for herself or himself.
We can explore the file system hierarchy by first understanding how to actually construct
the path of any directory.
So, forward slash is the root of the file system and also the ~~delivered~~ delimeter
for the subdirectories.
And in every directory there are two special files one is called the dot which is referring
to the current director and the other is double dot which is referring to the parent directory.
So, if you type the command cd space dot nothing will happen because you are trying to change
the directory to the current directory.
So, there is no change in the directly position.
If you type the command cd space double dot then you are going one level up in the file
system hierarchy.
So, you could ~~travel~~ traverse the file system hierarchy up and down by changing the
directory.
If you want to go from the user's home directory upwards you would say cd space double dot
and then you would be home directly and then series double dot you will be in the root
directory.
From the root directory if you actually give the absolute path you could actually go anywhere
you wish or you could actually use a cd with the name of the directory to traverse one
level at a time.
Let us explore the file system hierarchy using the system where we are trying to demonstrate
I become an environment.
So, where am I right now?
I am in the home directory of the user I am logged into and when I type ls I see that
there are certain files that are listed ~~herw~~ here and when I press ls space -a then we
notice that there are two special files here one that is dot and another that is double
dot.
There is a special directory called double dot which is allowing us to traverse one level
up in the hierarchy.
So, let me change my ~~director~~ directory to one level up and you would now see that
we are now in slash home.
And if I type this ~~comment~~ command once more then we are in the root folder verify
that we are in the root folder using the pwd command.
Now if I press cd then we are going back to the home ~~director~~ directory which means
that the cd without any arguments will take you to the home directory.
I know press control l clear the screen.
Now let me go back to the root folder and using ls we will see that there are certain
folders that are there in the root folder an get the -l option we can actually see the
long format and it actually indicates several things about the file system that we can already
start getting familiarized.
For example the very first character shows that there is an l here and for some directories
it is d and the difference between these two is that the l indicates a symbolic link.
So, which means that the bin folder of the root ~~territory~~ directory is actually a
symbolic link to a folder with the same name in the user directory and the d here means
that it is actually a directory by itself in the particular location.
Now boot directory the Linux kernel is located which is what gets executed when the system
is starting up and there are many such directors here let us explore one of them.
So, we will go to the user directory and then from there we can go down to the bin director
and let us look at what are the files that are there?
There is a lot of files that are here and many of these are actually commands that we
would be using as we go along learning the command line and environment and we can now
go back to the home directory verify that we are in the home directory.
In this manner we can actually traverse the hierarchy of the file system and explore what
is there in which folder.
Now let us look at the organization of these folders as per the file system hierarchy standard.
The bin directory in the root folder should contain the essential command binaries or
executables.
These are the commands that every user in the system are supposed to be able to run.
Sometimes this folder can be a link to the folder in slash user slash bin and that is
a matter of only a choice from the company that packages the Linux for you.
Boot folder contains the boot order which is what executes when system starts.
Dev folder contains the device file.
One says that in Linux everything is a file.
So, every device that is corrected to the computer is actually a file as far as the
representation is concerned in the file system hierarchy.
Etc folder contains configurations of various services which are specific to that particular
machine.
The lib folder will contain the libraries are shared programs as well as kernel modules.
The media folder will contain folders which are created when you insert a removable device
into the computer.
For example if you insert a usb disk then in the media folder a folder is available
this will contain the file system for the usb stick which you can explore and when you
unbound or eject the usb stick then that folder will also disappear.
Now slash mnt is a folder where you could have mount points that is directories which
are made available to traverse the file system of those respective hardware or hard disk.
Slash opt is a folder where application software packages are installed particularly in high
performance computing environment.
Run is a file system to have the data for the running processes.
Sbin is a directory where the executables meant for system administration are kept.
It is expected that normal users in the routine operation of the system do not require to
execute any command which is located in this particular folder, srv is a folder that contains
the data for ftp or http services, tmp is a folder where temporary files are located
every user will have permission to write files to this particular folder.
And one should not expect such files to be available after the rebooting because in many
computers the configuration would be such that upon reporting the slash time will be
cleaned up.
Slash user is a secondary hierarchy for the file system which is shareable by that we
mean when you have a high performance computing environment then you could have the user directory
shared across multiple computers.
So, that you do not have to actually have that much of hard disk uh space replicated
across all the computer.
Slash var is a folder where variable data is stored such as the log files for various
system services that are running in the background.
Now let us come back to the command prompt and look at these directories.
So, we go back to the root folder and you see that there is user directory and in that
there is a bin directory and you have got all these commands.
And we also noticed the slash etc.
So, look at what is all there in slash etc you would see that a whole bunch of files
are named as dot ~~con~~ conf which is basically the configuration for those respective ~~surfaces~~
services.
And slash var is a folder where we said that the log files will be located and they are
all in this folder called log and you would see that there are logs that are created for
various services.
Now let us look at the slash dev folder and you would see that the display would have
a different character in the long format of the file listing.
The c here shows that it is actually a character file which means that you could read from
that particular device a character by character which is typical of ~~uh~~ devices such as
the terminal.
And there are some files which would actually have the first character as b and these are
called as block devices particularly it is for the hard disks.
So, when you want to read from a hard disk you would read one block at a time typically
a block would be either 512 bytes or 1 kilobyte or even 4 kilobytes depending upon the configuration
and the Linux typically it is one kilobyte.
So, if you see these devices which are listed as sda 1 up to 7 these are block devices which
are available as files as far as the file system is concerned.
Let us look at the slash lib folder and you will see that this folder would contain many
files that would have a pattern which would have a number in the end which is typical
of a library files with version numbers that are there as a part part of the file name.
You can now explore the file system at your convenience and as long as you are using the
commands like cd and ls there is nothing that you can go wrong and make yourself familiar
with the file system hierarchy and understand which part of the hierarchy is your home directory
and everything below that hierarchy is what is owned and writable for you.
So, you could actually play around with it.
And you will notice that you cannot actually do much changes to the file system hierarchy
beyond your home directory which is characteristic of the secure manner by which the file system
is configured in the Linux operating system.
Before we wrap up let us look at the hierarchy of the user and var folders which is quite
extensive.
So, in the user hierarchy the secondary hierarchy you would have a user bin folder which will
contain commands that every user is expected to be able to run.
And there is a folder called user lib where library files are located, user local is a
directly where certain applications which are specific for that particular system are
installed which may not be common for all the operator systems in that particular variant.
User sbin is ~it directly~ a directory where system administration executables are located
but these are non vital because the vital ones are available in slash sbin itself.
What do we mean by that?
It is that when the machine is in a single user mode or in maintenance mode then executables
which are required to mount the file systems are performed system administration tasks
that are not dependent on any network or any remotely located file systems that are mounted
on the system then you would actually use uh slash sbin.
User share is a folder where the architecture dependent data is stored.
User include is a directory where the header files for C programs are all to be found.
So, when you started the helloworld program in C for example stdio dot h is a header file
that you include and you would see that it is located in this particular folder.
User src would be containing the source code of various applications that are installed
on the Linux operating system if you have chosen to installed those package.
The var hierarchy is also important because we need to know where to find the log files.
So, in var log the log files for various services will be located and in var temp some of the
temporary files that are to be preserved between the reports will be locate.
And vr log is a place where the log files are there for processes which would like to
have exclusive access to certain files during certain operations that prevent any clash
of information, var lib is a variable state information.
Now here is some logic or reason why there are such folders with this kind of a hierarchy.
So, what we mean by a shareable folder is that a file system which can be shared across
computers this is essentially to conserve the storage and also to provide uniform uh
file system to multiple computers particularly in high performance computing environment.
And sometimes you also have what is called the static and variable kind of file systems
or directories.
The static ones are ones which do no during the regular operation of the computer whereas
variable ones would change.
For example when an email comes a folder corresponding to that particular users inbox would change.
So, that would be in the variable folder such as var by mail by the user name.
However when you execute commands the executables are not going to change and they will always
static files there are some folders which cannot be shared across computers because
they contain configuration specific to that particular computer.
Slash etc and slash put are some such folders and there are some such folders which are
not shareable across computers as well as they are also variable with the regular operation
of the computer like for example var lock or var run
So, this is a logic why there are different folders and a standard has been defined to
ensure that users who log into machines can actually identify these folders irrespective
of the specific version of the operating system they are using.
And across the Linux variance you would find that the file system hierarchy is maintained.
And this helps us navigate the file system hierarchy and locate the files that we are
looking for to execute them or to use them for linking purpose while we compare some
of our programs.
I hope you got a sense of the file system hierarchy and I urge you to explore the command
line environment and make yourself familiar with the file system of your own computer.
And you would soon be comfortable with locating files that would arrive onto your computer
as you run commands or download things and move around the files for your work.
Weitere ähnliche Videos ansehen
5.0 / 5 (0 votes)