0% found this document useful (0 votes)
13 views16 pages

Lecture 2 - Command Line Environment

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views16 pages

Lecture 2 - Command Line Environment

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

System Commands

Online Degree Programme


B. Sc in Programming and Data Science
Diploma Level
Prof. Gandham Phanikumar
Department of Materials Engineering
Indian Institute of Technology- Madras

Lecture 2
Command Line Environment

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 environment.

So, the command line environment should be seen as not only a way by which you type
out instructions to the computer but also as a path towards automation.
(Video Start: 00:59)

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 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 ask ing 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 batch that is
running. So, our shell that we are interacting with using this terminal emulator is batch
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 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.
(Video End: 05:36)
(Refer Slide Time: 05:37)

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 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.
(Refer Slide Time: 06:11)
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 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.
(Video Start: 07:22)

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 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.
(Video End: 09:14)
(Refer Slide Time: 09:15)

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.
(Refer Slide Time: 09:29)
Now the manual pages come in many sections and this is just a textbook inform ation 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.
(Refer Slide Time: 09:47)

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.
(Refer Slide Time: 10:04)
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? 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 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.
(Refer Slide Time: 11:49)
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.
(Refer Slide Time: 12:53)
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 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 the file system hierarchy up and down
by changing the directory.
(Refer Slide Time: 13:43)
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.
(Video Start: 14:14)

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 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 to one level up and you would now
see that we are now in slash home. And if I tight this comment 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 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 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.
(Video End: 17:02)
(Refer Slide Time: 17:03)

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.
(Refer Slide Time: 18:49)

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 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.
(Video Start: 20:14)
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 which is basically the configuration for those respective surfaces.

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
service. 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 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 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.
(Video End: 22:58)
(Refer Slide Time: 22:59)

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 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 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.
(Refer Slide Time: 25:33)

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 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.

You might also like