Friday, September 7, 2007

Second Lecture OPS435

First Week Second Lecture
OPS435C
Frank C Russo

Directory Structures, in Linux its not much different from many other systems if you want to understand this its easy to remember because its similar to your family structure, parents, grand parents, to your children and grand children

Databases contain information which is located in different directories this is where the directory structure comes from, this starts from root,

Typed cat dir.sir…showed a detailed directory

An example of linux directory structure it starts at the very top with root and under root you can subdirectory and files, and each of these can have their own subdirectories and files, when you address a file or subdirectory you have to tell the system where the data is located, there are two different ways, one is called relative and the other is absolute, absolute addressing from root always, relative starts from where you are Current Working Directory, if you need to use a command you can mix the two, part in realitive part in absolute, there are many instances you must have it in one or the other, if you addressing the /etc/passwd, you can do in relative but it takes to much time be efficient, and since you know where it is you can use absolute addressing to get to this file, any thing that the program creates should be in relative, because if you create a program you don’t know the other persons directory structure this makes all the data go in the right place correctly. You must know when to use what. In our assignments it will become clear, lets make sure how each one works, this is a review we must understand how to access databases,

For instance you want to change the directory from where ever you are to go to your home directory what command do you use? Cd command with no arguments takes you back to directory, if you add a ~ (tild) it takes you home or $HOME it’s the same thing, the shortest command to use is cd, with three simple commands you can navigate to structure,

How would you know what dir you in pwd, the files to list ls

Lets assume your current directory is steve how would you change your directory to steves parent which is usr, type cd .., cd ../.. (grand parent directory) in our case would be root,
Think current address is steve
Relative ..
Absolute /usr

What is the A and R address for math
Relative from usr program/math
Absolute /usr/steve/programs/math
The shell automatically starts from the current directory

Subdirectory data from steve, up one then across
Relative ../john/data
Absolute /usr/john/data

Remember that the command line is case sensitive, with 99% we are going to use we are going to use data from the database, so you have to address data from the database, KNOW REALITIVE AND ABSOLUTE, quiz one will have a lot of both….make sure to review.

Linux system directories, in the Linux strcture there are number of directories these are what they are and what their used for
/bin = holds binary executables
/boot – holds the Linux Kernel
/etc – contais configuration files
/home – the default home directory for users ($HOME)
/lib – contains library files
/mnt – contains mounted drives (can mount structures to other ones or as a part of your own)
/root – the root user’s home directory
/tmp – contains temporary files
/var – contains files that change

/  all encompassing root directory
/root belongs to the user root

These are all in each Linux system

Examples :
Cd brings us to your home with a ~ tild is the exact same thing
~john - brings you to johns home
~/john - brings you to ur home directory to a subdirectory john

The Shell automatically replaces the tild when it does the interpretation of the command to what ever the home directory is, it will replace the variable name with the content which is your own home directory

When you execute any commands the requirements of a command most will require an input of some sort, by the user or system itself, if you do an who, the input to this command is provided by the system itself, it provides an output, theirs an STNINP then STNOUT ….where does STNOUT go it goes to the screen by default STNOUT goes to the screen, unless you direct it somewhere else, STNINP where does it come from…the keyboard
Type

Cat file
Where does STDIN come from…it comes from the file, you have told the command to get the STDINP from the file and STDOUT put comes from the screen,
Cat …with no arguments
It waits for input (keyboard by default), it comes from input Ctrl-D takes you to the next line.

STDIN STDOUT & STDERR

Where does STDERR go to by default…on the screen, so you can see it.

Those are the three things we need to understand.

Special Characters the shell interrupt all special characters

< - Redirect STDIN this is also known a file descriptor, there are three file descriptor

0< STDIN whether you put the zero or not it knows

1> 0 Redirect STDOUT

2> STDERR

Knowing this what would happened if you redirect a file a into c, if you follow the cat command will read the contents of a then go to b then it will produce a STDERR then the STDOUT it will go into the file c you will not see the STDERR and if you execute it you only see the STDERR

Cat a b > c
Error!

Cat a b 2> c

You will see the contents of file a and the error b will go into c and you will find the error in c

What happens if we want to send both,
Cat a b > c 2>&1

Theirs two different way to redirect both STDOUT and STDERR this formation works in every system in every shell, this is standard, 2> redirect STDERR &1 to the same place to STDOUT was redirected, nothing appears on the screen, and if you cat the c file you see both.

Rmdir –r – remove that directory recursively all of them

Permissions, ls –l

Read
Write
Execute

Ls –l
O G N
- RWX RWX RWX

- - File
D – directory

Owner Group Name

Ls –l tells you what group you are in….
For a file you can read, the contents of a directory you can see directories, a directory does not contain files or subdirectory, it contains the names of the files of the subdirectories, when you reading the contents of a directory you are reading the names of the file and subdirectory, so if you have read permission, you can use LS for a directory for a file it would be CAT,
To write into a file you need write permission, when do you need to write into a directory, if you create a new file, you are adding a name to the directory, you are modifying the contents of the file, if you delete a file you are taking the name out for those you need write permission for the directory,
X execute it allows you to execute a file, better be a program or a script, how about a directory can you execute a directory, the X has a different meaning to a directory then from a file, what is this meaning for the X for a directory you are allowed to get into the directory the X is a the key to get into the room, think a closed door, if you do not have a key to open the door you cannot read the file.

X – pass through permission, allows you to go through it

Cat / home /joe /dir /f1
X x x x r -minimum permission for the command to be successful
.
Cp / home /joe /a ., /b
X x x r x w - u need to read to source and write to destination
If it doesn’t exist (b) you need to write permission in the home directory

Cp / home /joe /a? .. /b
X x xr r x w

The moment you put a ? is will read the contents of more then one file so the directory joe must have read permissions in order to read and match the files.

Tips: Look at every directory ONE at a time, any time you are using file name expansions character ? * [] you are asking the shell to match, so the shell has to have read permission to read the contents of directory.

We are going to be using vi so go through vi stuff.

Copy command you must have a minimum of two arguments
Cp a b c d
Copying it into a directory, more then one file you have to copy it into a directory

-I - Interactive, it asks you for each file

The move command mv, same as the copy command

Handout

When the shell interprets it interprets every line and goes through 9 steps each and every time, these are the nine steps the shell goes through….

Know the 9 steps
1. Token Spitting: When the shell looks at the command line breaks it up to each individual word and looks at each one, one at a time…happens with every command line
2. Alias Substitution: Known by many different name, in Linux you can create new commands in Linux you can have a regular command even Ls and give it another alias, when the shell looks at the command it checks to see if it’s a real command or a alias command…greater detail in later Lectures.
3. Tilde Subsitution – Looks for the tild its going to replace it with your home directory
4. Command Subsitution – Greater detail later, you can have one command inside another and into another one, like the algebra you look from the inside out, same thing happends with this process the shell takes a look at the special characters and tells it command substitution,

When we introduce special char jot them down, when you have a command inside backquotes this is command substitution, the shell must execute it first, replace the command with STDOUT of the command, another one is dallor parenthesis is the same thing
‘ banana’
$(banana)
5. Parameter Expansion: The special character for shell variable expansion how does the shell know it’s a variable name and not text…with the dollar sign $var when it replaces the variable name with the contents its done in #5
6. Wildcard Expansion: What character is it looking for examples * ? [] those are the three characters its looking for in this step, when it encounters them it will go to the directory and replace them with the files that it has matched
7. Quote Processing: What characters are quoting characters their single double and the other is a backslash

‘’ (single quote) – in Linux anything inside this does not have any special meaning, no special characters what you see is what you get.
“” (double quote) – same as single quotes with three exception, there are three characters that retain their special meaning in double quote which are $ ‘ \ dollar sign, single quote, and backslash

Try something
a = 1 2 3

To read this echo $a and it will echo the contents 123
Echo “$a” view 123
Echo ‘$a’ view $a

The meaning \ its called a single character quote. Backslash the character following me is not a special character,
Echo \$a view $a - the shell will not interrupt $ as a special character because of the \ (backslash)

\\$a view \123 …. \ makes it so \ is not special following everything executes itself

8. I/O Redirections : STDOUT STDIN STERR, it will do the redirection when found, but when the shell….do this
Sort f1 > f1 - when you do this command before the command is execute the moment it encounters its going to clear the contents of the file then you are sorting Nothing and you redirect nothing into f1. This step is done BEFORE its execute

9. Execution: Command is execute : most of the time the kernel execute the command the only time it doesn’t if those commands are part of the shell a number of commands are apart of the shell, when the shell is in the memory what ever is in the memory you don’t need it to bring into memory then to shell, those get execute in the shell, theirs a list of the command they are 20% of the commands 70% is executed into the kernel.

How does the Kernel know where to find the command, the shell goes to path variable searches through all the directories and searches where the utility is located, execute this command and this is where to find it, the kernel copies the command to the database to the memory goes to the memory then goes back to memory then it goes back to shell and then asks the user what they want to do again.

No comments: