Today we have learned some simple commands to navigate through linux. The CD was brought up and that by default takes us to our home directory. But when used with a directory name it will take us there. Also learned how to change permissions on each file. Its kinda confusing how the numbers work but i believe i can pick it up pretty fast. Also learned other simple commands like ls and pwd and who. ls list files in a directory, pwd tells you where you are and who tells you who you are.So we basically just learned some basics and concepts of how files work. Also set up class chat. In cprog I have read chapter one of “the C programming language”. I learned simple things like printf to say hello, and showing variables and arithmetic. I wrote one or 2 simple programs but that is about it so far. Nothing seems to difficult so far
In linux we focused mainly on using the text editor Vi. It is moded text editor unlike most. Both the command and insert mode are completely separated from each other. So instead of using nano, we have learned to use this. There are various commands to do number of things. You can jump words, or letters or sentences and so much more. It is a confusing editor i will agree but if i play with it some more i believe i can get better with it. practice makes perfect. But pretty much with vi i just need to play to figure out what commands i truly need to know and what i could use. Other than that, this class is going well so far with some new commands like date and cal. Can get really general or specific. In cprog i have read chapter 2 of the book and it talks about declarations,operators, conversions and etc. I am going to re-read this section i believe because i am in a rut with it and i would like to get this down so i can start projects here soon.
In linux we have learned about process id's (Pid). they are basically a small id for any process that happens to be running. So anything you are doing at that moment has a pid. With that you can go in a maniupulate it in some way. Thats when we learned the kill command. We take the pid of the process we want to kill and we just kill it. They are numerous kill options but we prefer kill -9. We also learned that there is such things as zombies. Expected zombies we can take care of but an unexpected zombie is something we do not want period. so we learned how to make expected zombies, find processes with any specifics and a little more on vi and a similar editor that i cant remember. In cprog i have chapter 3 but likewise i am going to re read it. The concepts are kind difficult but im just going to take a day and do sample programs till i understand fully or well enough.
In linux today we learned shell scripting. You basically run the system from the outside instead of the inside. We wrote some simple scripts like one will ask for our name and say a message. Then another one asks for a password. either the password was in the script or it called another file with the password we wanted. We learned what we needed to do, what means what like # stands for a comment. #! this is a shhh bang!And we made them executable with a new way of changing permissions. He gave us one more program which took any files in a directory and got rid of any extensions and made them all just regular files, no extensions. Cprog i have moved on to chapter 4 and its about functions mainly. I understand functions so its no problem but i believe at this point, i can start doing projects. I still need to go over a few chapters though, some things are still a little iffy for me.
In standard I/O you have STDIO, STDOUT and STDERR. STDIO is you communications stream, your user input. It is attached to your keyboard and whatever you type in, the input will read it and take it and store it in its memory. STDOUT is attached to your command window and it will print out data onto to your display window. STDERR this is also attached to the command window and it is there to display error messages when things go wrong.
Header files are files that allow programmers to seperate certain elements into reusable files. Header files commonly contain forward declarations of classes, subroutines, variables, and other identifiers. If programmers wish to use more than one source file they can put it into one header file, and it can be used throughout each source you wish to use these reusable files.
There is a lot of arithmetic going on in the language of see but your most common is conversion arithemetic. Most C operators perform type conversions to bring the operands of an expression to a common type or to extend short values to the integer size used in machine operations.
float fVal; double dVal; int iVal; unsigned long ulVal; dVal = iVal * ulVal; /* iVal converted to unsigned long * Uses step 4. * Result of multiplication converted to double */ dVal = ulVal + fVal; /* ulVal converted to float * Uses step 3. * Result of addition converted to double */
There are a lot of operators that can be used in the C world. You have logical operators such as AND, OR and NOT. These are choice operators like if you use AND both must be true in order for the code of program to work. With an OR one or both must be true to work. And NOT Just says you can not be eqaul to this and it will work. You basic opartors such ass addition, subtraction, multiplication and division. These operators are there so you can complete the logic needed to fullfill your program. Without the operators, you could not do the program logic.
This is where a program can or cannot touch. It has the global scope, where variables can be declared for the entire program to see and use. Then you have a local scope where variables are declared in a function and can only been seen and used with in that function.
global:
#include <stdio.h> int ginteger; float globalfloat; int main () { exit (0); }
Local:
#include <stdio.h> int main() { int hi; float a, b, c; exit (0); }
This is a collection of same type of elements. it can hold more than one variable and can be used to organize numbers, sort, count or many other uses.
<data type> array_name[size_of_array];
You can initialize the array once you declare it if you know what you want to go in there but if not, you can put values into there throughout the program.
Variables are the things are created along with a data type. When you use a dat type such as int or char, you assigned it a variable. So you will have something as simple as “int = 6” or something as that. The int is being declared to a variable of 6.
Formatting a string in a program is easy when you use the function printf(). The format string specifies a method for rendering an arbitrary number of varied data type parameter(s) into a string.
printf("Color %s, number1 %d, number2 %05d, hex %x, float %5.2f, unsigned value %u.\n", "red", 123456, 89, 255, 3.14159, 250);
basically when the printf function is used, it can print out whatever character you use into one string that will be displayed onto your screen.
In order to do file access you need the function fopen(). Now this function will open up what is inside the file. You can also write and append to this. To append to the file you need the fopen() with “a” permission and to write to a file you need fopen with “w”. Now these are just the simple things you can accomplish with fopen.
#include <stdio.h> int main(void) { char buffer[256]; FILE * myfile; myfile = fopen("some.txt","r"); while (!feof(myfile)) { fgets(buffer,256,myfile); printf("%s",buffer); } fclose(myfile); return 0; }
Every language has a function either it is called subroutine or procedure, there is a function. In C it is called a function. A function is used to do seprate logic operations outside of the main so its not so cluttered. Then in the main you can call the function and use it like you would regular functions like printf(). They can either have a return value or no return value, depending on what your program is asking for.
double power(double val, unsigned pow) { double ret_val = 1.0; unsigned i; for(i = 0; i < pow; i++) ret_val *= val; return(ret_val); }
These parameters can be of any type, data types that have been defined by the programmer. As long as the C compiler can locate the types (i.e. they are in scope) at compile time, then any can be used. A parameter can be passed by reference or by value. When passed by reference it can be altered inside the function. When it is passed by value it can not, only a copy of the value is passed on. Depending on how your program is, you can choose one or the other that fits it best.
The return type of a function establishes the size and type of the value returned by the function. This is basically what kind of datatype you will be receiving from the program. You have many types like int, typedef, void, char, short, float, double and many other things. All these are return types and can be used in just about any program language.
Regular files in linux are just common files in the linux system. They basically hold data and text and even binary data. regular files hold a dash next to the permissions to show that it is a regular file. They are also white, white is the color of regular.
The ls command lets you list what files and/or directories are located in your current directory. It can be listed in many different ways and it can either just tell you the name or give you more detailed information.
lab46:~$ ls Maildir bin contact.info.save destructo.sh hey hi.c lab1a.text newdirectory public_html soaringeagle1.sh tmp a.out closet data hello.c hi killerwasp.sh motd pss soaringeagle.sh src lab46:~$
A directory is a blue file you will see on your linux terminal, in the home. Now these type of files hold even more files that the system runs or they just can be extra files that you want in a common place. Like you will want data1, data2, data3 and data4 all in one place. So you will place it in a directory called “DATA” and that will be a blue file that can now hold those and anything else you want to stick in there.
Special files are also known as device files. Two kinds exist: buffered device files and unbuffered device files. The buffered special device files are called block device files; the unbuffered ones are the character device files.
So links are called symbolic links as well. And basically you “link” two files together. When you do this you use the “>” to give an absolute path you want the file linked to. So i can take my home directory and link it directly to another directly or whatever you need to do. Links bring files together easily.
As a user you have file permissions. You have all full permissions in your home directory mainly because they are your files. Now you can have permissions over other things as long as you are allowed to have these permissions or you are the superuser and can do what you want. Now in order to change the permission of a file you can use chmod. now yo have a rwx for user, group and other. User is what permissions you have, group is the permissions others have and other are just system permissions. Now with chmod you can do 2 things either change it with letters or numbers. you can do something like 474 or do like -x, -r, -rw, -. or whatever combination. here is an example of what i do:
lab46:~$ touch jesus lab46:~$ chmod -x jesus lab46:~$ ls Cexetension.tgz a.out invaderzim public_html Desktop badname irc puzzlebox Documents badname.tgz jesus puzzlepaper Downloads bin lab1a.text regularexpressions FilelistforOPTAR candy motd scripts Maildir classlog12 networkcmds spring2012-20111103.html Music contact.info.save newdirectory src Nyan Cat.wav courses out test Public data outfile test2 Schedulecut dl output tmp Templates hiopus pgm2ps unixprog Videos in pss wildcards lab46:~$
To change the ownership of a file you use chown. You can use this to make a file used by user only, or by group only or a mixture of the 2. If only an owner (a user name or numeric user ID) is given, that user is made the owner of each given file, and the files' group is not changed. If the owner is followed by a colon and a group name (or numeric group ID), with no spaces between them, the group ownership of the files is changed as well.
In linux you can easily view a file with the command of cat and less. Cat looks in a file and displays the data onto the command line prompt for you to see. Now the less is there if the data is like really huge, it makes it so it is much easier to read on the screen. Just makes it better. Here is an example:
lab46:~$ ls Cexetension.tgz badname jesus regularexpressions Desktop badname.tgz lab1a.text scottysnumber Documents bin motd scripts Downloads candy networkcmds spring2012-20111103.html FilelistforOPTAR classlog12 newdirectory src Maildir contact.info.save out test Music courses outfile test2 Nyan Cat.wav data output tmp Public dl pgm2ps unixprog Schedulecut hiopus pss wildcards Templates in public_html Videos invaderzim puzzlebox a.out irc puzzlepaper lab46:~$ cat invaderzim yep... DIARRHEA lab46:~$
The Insert mode is what you'll work in most of the time. You use it to make changes in an open file. Enter the Insert mode by pressing the I key. Newer Vi versions will display the word “INSERT' on the bottom line while you're in Insert mode. Here is an example real quick:
1 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ -- INSERT -- 0,1 All
Now when in here you mainly just type out what you want and when you are to finish off this editing hit the esc key to enter back into command mode, where most commands to like save will be held.
The program opens in the Command mode, which is used for cursor movements, delete, cut, copy, paste, and saving changes.
1 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 0,0-1 All
Looks very similar to insert mode just with the big word, insert. This is where you will execute your commands such as save and delete and start a new line, etc. You will have commands like ”:wq“ for save and quit or “q!” for quit without saving. As you learn this more and use it more and just play with it, you will learn a lot about what commands are in this. Not even i know how many commands are on this thing, as a student i am still learning. there are man pages though do not forget. here are some commands you can find on the man page:
Press Key(s):* Function:
I Insert text before the cursor
A Insert text after the cursor
: Switch to ex mode
$ Go to last place on the line
W Next word
B Previous word
Shift-G Last line of the file
20 Shift-G Go to line 20
Y Copy. (Note: Y3W = copy 3 words; Y3J = copy 4 lines.)
P Paste
D Cut
X Delete character under the cursor
The extended or ex mode is similar to an independent line-oriented editor that can be used for various simple and more complex tasks. The commands you would have in here are:
:q – quit without saving
:q! – quit forcefully without saving
:w – save
:wq – save & quit
:wq! – save & quit forcefully
:sh – provides temporary shell
:se nu – setting line numbers
:se nonu – removing line numbers
:84(enter) – goes to line number 84
as you see to enter the extended mode you use the colon and gives you extra commands then the simple ones found in command mode.
The UNIX shell is a place where the user enters commands to the command line and scripts within this shell are executed by programs in files. Now the shell and unix itself are files, everything is a file. You can write shell scripts to customize how you want the shell to act and look like. Now the shell we work in is the C shell. It is written in the language of C and is highly compatible with the language source code. So you can easily program on this shell if you wanted to. The shell is basically where you work with the files and manipulate them. The shell is just there to hide the kernel, the heart of the operating system. The shell is here to make the lower level systems easier to manipulate and use.
know the difference between structures and classes. A struct has members that are public by default and can be inherited by public as well, while a class is private by default and is inherited privately as well.
I will show this program through a sample program that should hopefully prove the difference of struct and classes.
#include <stdio.h> class A { public: int a; }; struct B > A { }; struct C { int c; } class D > C { }; int main() { B b; D d; b.a = 1; d.c = 2; }
reflecting upon objective
Familiarity with the structure of UNIX systems. This is basically stating what the unix system is and in its entirety, its a hierarchy of files. Everything has a file of some sort and is run through files.
I will use commands on the command line to show the different files and how you can go deeper and deeper into files, just showing how its all connected in some way.
lab46:~$ cd .. lab46:/home$ cd . lab46:/home$ cd .. lab46:/$ ls bin etc lib lost+found opt sbin sys var boot home lib32 media proc selinux tmp vmlinuz dev initrd.img lib64 mnt root srv usr lab46:/$ cd lab46:~$ ls Maildir contact.info.save hi lab1a.text soaringeagle.sh a.out data hi.c motd soaringeagle1.sh bin destructo.sh in newdirectory src botopen hello.c irc pss tmp closet hey killerwasp.sh public_html lab46:~$ cd lab46:~$ cd src lab46:~/src$ ls Makefile cprog discrete submit unix lab46:~/src$
Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.
What would happen if i moved the tmp file into my own home directory?
My resources for this will be for class, there is no need for further information on it
First my objective is to see why the tmp is highlighted in the root directory. We are going to see what happens when i move it. In its original directory it is highlighted for some reason and im going to see if it disappears when i move it. I believe it being highlighted will disappear when its moved over to my directory.
Im going to show the tmp file. then show the commands im going to use to move it and/or copy it over. and show it within my home directory.
lab46:~$ cd .. lab46:/home$ cd .. lab46:/$ ls bin etc lib lost+found opt sbin sys var boot home lib32 media proc selinux tmp vmlinuz dev initrd.img lib64 mnt root srv usr lab46:/$ mv tmp home mv: cannot create directory `home/tmp': Permission denied lab46:/$ cp tmp tmp1 cp: omitting directory `tmp' lab46:/$ ls bin etc lib lost+found opt sbin sys var boot home lib32 media proc selinux tmp vmlinuz dev initrd.img lib64 mnt root srv usr lab46:/$ cd tmp lab46:/tmp$ ls fishd.log.cforman fishd.socket.cforman hsperfdata_bh011695 img--03883.asc fishd.log.critten1 fishd.socket.critten1 hsperfdata_bstoll lost+found fishd.log.root fishd.socket.root hsperfdata_dschoeff script fishd.log.vcordes1 fishd.socket.vcordes1 hsperfdata_mgough fishd.log.wedge fishd.socket.wedge hsperfdata_rmoses lab46:/tmp$
The tmp directory in the root directory of the system cannot not be moved or copied to another directory. It hs files that will create when they are needed and be deleted. The reason its highlighted, to my understanding, is that it cannot be touched by any users unless you are admin on the server. so in the end, i am unable to change or move any files that have that kind of highlighting.
Can you kill someone elses process?
I will be usuing information i have learned in class.
I believe if the permissions allow it, i can kill any process on anyone's terminal.
All i need to do is find the processes using the ps aux command and it should show everyones process id's, then once i find them all i need to do is kill it with the correct pid.
I am going to try to show through the command line at home. if i can not i can explain what will happen.
lab46:~$ ps aux | grep SCREEN bewanyk 1052 0.0 0.0 62752 868 ? SNs Sep16 0:01 SCREEN dschoeff 1151 0.0 0.0 62872 1020 ? SNs Sep16 0:01 SCREEN abrunda1 1195 0.0 0.0 62636 616 ? SNs Sep16 0:01 SCREEN bh011695 1200 0.0 0.0 62744 1008 ? SNs Sep16 0:02 SCREEN irssi mgough 1283 0.0 0.1 62720 1100 ? SNs Sep16 0:02 SCREEN mowens3 1467 0.0 0.0 62212 528 ? SNs Sep16 0:00 SCREEN tgalpin2 1945 0.0 0.0 62476 476 ? SNs Sep16 0:00 SCREEN mshort3 2112 0.0 0.0 62344 520 ? SNs Sep16 0:01 SCREEN lburzyns 2329 0.0 0.0 62212 224 ? SNs Sep22 0:00 SCREEN kkrauss1 2616 0.0 0.1 62796 1136 ? SNs Sep16 0:03 SCREEN qclark 3171 0.0 0.0 63276 28 ? SNs Sep29 0:00 SCREEN asowers 3454 0.0 0.0 62628 540 ? SNs Sep16 0:00 SCREEN afassett 7756 0.0 0.0 62212 336 ? SNs Sep18 0:00 SCREEN vcordes1 7769 0.0 0.0 62344 164 ? SNs Sep28 0:00 SCREEN -a syang 7902 0.0 0.0 62740 196 ? SNs Sep28 0:00 SCREEN qclark 8037 0.0 0.0 62344 12 ? SNs 16:28 0:00 SCREEN asowers 10361 0.0 0.0 62212 160 ? SNs Sep29 0:00 SCREEN dherman3 11940 0.0 0.0 62212 220 ? SNs Sep27 0:00 SCREEN kreed11 12067 0.0 0.0 62516 336 ? SNs Sep22 0:00 SCREEN sweller5 14219 0.0 0.0 62204 172 ? SNs 13:22 0:00 SCREEN jhammo13 18902 0.0 0.0 62212 152 ? SNs Sep19 0:00 SCREEN dgirard3 18923 0.0 0.0 10088 868 pts/66 SN+ 23:37 0:00 grep SCREEN kinney 19066 0.0 0.0 62204 408 ? SNs Sep19 0:01 SCREEN mtaft4 20336 0.0 0.0 62212 288 ? SNs Sep19 0:00 SCREEN nsano 22657 0.0 0.0 62344 420 ? SNs Sep20 0:00 SCREEN jjohns43 22802 0.0 0.0 62488 664 ? SNs Sep20 0:02 SCREEN ccaccia 23078 0.0 0.0 63288 1032 ? SNs Sep20 0:13 SCREEN lgottsha 23923 0.0 0.0 62512 612 ? SNs Sep20 0:00 SCREEN -a dgirard3 24243 0.0 0.0 62212 320 ? SNs Sep20 0:00 SCREEN cforman 24589 0.0 0.0 62344 484 ? SNs Sep20 0:00 SCREEN csteve16 25457 0.0 0.0 62212 156 ? SNs 14:40 0:00 SCREEN drobie2 27767 0.0 0.0 62360 868 ? SNs Sep21 0:00 SCREEN critten1 27783 0.0 0.0 62212 272 ? SNs Sep20 0:00 SCREEN acanfie1 27943 0.0 0.0 62580 660 ? SNs Sep18 0:01 SCREEN -l rlott 28620 0.0 0.1 63300 1316 ? SNs Sep22 0:00 SCREEN jr018429 29483 0.0 0.0 62212 292 ? SNs Sep18 0:00 SCREEN swilli31 30392 0.0 0.0 62212 168 ? SNs Sep29 0:00 SCREEN lab46:~$ kill -9 25457 -bash: kill: (25457) - Operation not permitted lab46:~$
i used the grep command to find process only with SCREEN in the name
Based on the data collected: I cannot kill someones terminal using a simple kill command
Basically in the end, one can not simply kill someone elses terminal or process. You can only kill your own or if someone changes their permissions on it, then it can be done. But other than that, nothing will change.
Can you make a script to run simple commands?
Im just going to use info from class.
I believe with the right script you can easily issue a command from a script. A script is a program that can run outside the shell, looking down it. It can control what happens with the right coding and other little commands.
I will show my script on here then show in the terminal running.
lab46:~$ vi soaringeagle1.sh lab46:~$ vi lab46:~$ vi exper lab46:~$ vi soaringeagle1.sh lab46:~$ vi exper lab46:~$ ./exper -bash: ./exper: Permission denied lab46:~$ vi exper lab46:~$ ./exper -bash: ./exper: Permission denied lab46:~$ chmod u+x exper lab46:~$ ./exper -bash: ./exper: /bin/bas: bad interpreter: No such file or directory lab46:~$ vi exper lab46:~$ ./exper ./exper: line 2: Maildir: command not found ./exper: line 3: return: can only `return' from a function or sourced script lab46:~$ vi exper lab46:~$ ./exper ./exper: line 2: Maildir: command not found lab46:~$
My script was a simple #!/bin/bash with a expansion on the ls command connecting to the home directory. However it is saying i have no permissions to do this.
Based on the data collected:
In the end, i believe my script is wrong. It was a simple script but it may have been written wrong, but regardless what i took from this is that you shouldnt make a script to run a simple command when you can just type the 2 letters. But i believe there is a way to do this so i do believe this was a fail experiment but can deffinitly be looked at again in the future