Alex Hughes' spring 2013 Opus
'A straight line may be the shortest distance between two points, but it is by no means the most interesting…' - The Doctor
I have a Bachelor of Arts in Psychology from SUNY Fredonia. I'm at Corning for Computer Science now so that I can eventually lead my way into Human-Computer Interaction. I initially went to school for Music Education, Upright Bass was my Primary instrument, I also can sing, play guitar and a little bit of piano.
I'm SUPER NEWB at Computer science, only really got into it last semester.
But Like most Computer Science people I am a very large nerd. I like Video Games, Doctor Who, Anime, Magic…etc….
This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.
As an aid, feel free to use the following questions to help you generate content for your entries:
The Command Prompt is the super magical spellcasting area. It's where you summon your creatures for battle, your sorceries and enchantments for stat buffers and where you play instances that can interfere with your opponants strategy(well, maybe not that lst one, but you get it. )
prints the name of the host user commanding the prompt, IE the name of your spellcaster. IE,My name is alex, but on skyrim I have a character named Improper Grammar Dessimator. (because to Dessimate, one only needs to have to attempt to correct improper grammar.)
this copies files
this moves files
This removes files (in magic, it would remove it from the game)
this is the root, the root of the filesystem in which you can make a pathway to other files, like the front door of your house.
This is the starting point to which you connect to other files (like walking into the front of your house, as you step into the living room, the code would be:
=If you were to want to travel to the sofa in the living room, the code would be:= ='/living room/ sofa'=
=notice how you would have to start at the root '/' then enter the living room, and from there sit on the sofa.=
=RELATIVE VS ABSOLUTE Path:=
=the last example of '/living room/ sofa', is considered to be an ABSOLUTE path, because one has to start at the front of the house.=
Now Consider: 'sofa/living room/' this would be considered a a RELATIVE path because you are starting from the current location and then continuing onto a different location, from the sofa in the living room to just standing in the living room
This command tells this system that you are leaving your current location so, say if you were in the living room. by entering
this would imply you leave your living room and continue into the kitchen, because the kitchen is not in the living room(unless you live in one of those super cool 10×10 studio apartments in NYC, in which case, every room is in one)
This is an acronym for “print working directory” This tells you where you're at. So after a long night of drinking hard, you might wake up in the morning and be like “where am i ?!”. By using this command it will hopefully tell you are in:
but sometimes it may be:
In which case you may want to lay off the drinking so much, but that's besides the point.
This command creates a new directory, kind of like creating an addition to your house, the name of that addition is what is placed in the argument so say if you were in your living room, and you just bought a coffee table to hold all your super awesome gamer magazines you would cast these:
When already in your living room, you place the coffee table there. the code would be:
this creates directory in the existing directory, much like the different room of the house, but there are things in some rooms that aren't in others.
this stand for change directory if you were to take the last example, were already within your living room and used this command:
it would take you out of your living room and shrink you down into the coffeetable. (insert some benign “Honey, I Shrunk the Kids!” Reference here)
ls stands for list, which simply lists the contents of a directory. So if you were in /living room/coffeetable and then commanded ls, it would be like :
GamerWorld, You play games too?! etc.
====2/1/13 Alex Hughes 'Mage ch. 3.' 'Basic file and directory copying and navigation'====
This Creates a blank file. to know if something is a file and not a directory, use *cd* and the name of the thing you wish to see if it is a file. If cd fails, then it is a file.
the - calls an option of the command '-F' makes the command 'ls' list only the files in the current directory you are in.
an interactive command that produces a text editor
='^' = control key=
Splits the content of the file to the terminal so when you use nano to edit a file, the text you put into the file will be spit out into the terminal with cat
a interactive command that supports paging paging uses the command 'more' and 'less' to navigate
copies the file into the other file.
Moves the file named to the location from the files current location
='sending files to the grave'=
Removes file
removes directory
—>option '-rf' - stand forrecursive force, which keeps the prompt from asking wether or not you wish to delete the directory and automatically deletes it.
prints all typed and entered into prompt by the user.
Pressing the 'Tab' key once with the condition of letters will show you the commands entered with those letters
with Bash:
with other Shells:
..
RTFM (Really Try For Myself)(Read the fucking manual) -Try to solve the Problem or find the information for yourself before you ask for help, when others ask of you for your help, give willingly your time.
This command accesses the user manual and prints the reletive information about the command name.
Any one of these are page viewer programs, which are opened with the use of the command, the most popular that being of 'less'
_In man, '/'( pattern ) <return>_
This searches man for a pattern associated with a word, to enact the search throughout the manual for this pattern, you have to press retuen, or enter.
goes to the next pattern in the search,
will go back
will allow you to open up another man terminal whilst already in one.
this tells UNIX what section of the manual to look for the command. the number being a different section, each with their own specific levels of commands.
=(this may need -s before on some systems)=
=or 'whatis (command)'= This only shows the description, instead of the whole manual page
=or 'apropos manual' (keyword)= This searches the manual for all encompassing strings that match your keyword, including other commands that use that keyword.
or =='man info'= =_the 'info' manual allows information to be linked and to access those links to further access more information, unlike 'man'=
=much like that of a website. (ughh, but it was developed by the emacs developers…)=
_1.Ordinary_
- Contains data, most of the files that the user works/ interacts with. - 2 types, text and binary.
_2.Directories_
- I pitty the fool who doesn't organize their files in directories. - Essentially directories are pointers to other files, or other directories, that point to files.
/proc - this goes to the proc file directories, part of the pseudo files below. ls /proc to list them files !
_3.Pseudo Files_
- These files are service files, they access the kernal and central elements of the OS. - Special: In the category of Pseudo Files there are SPECIAL files, which are primarily device files.
- Pipe. Another type of pseudo file is that of a pipe, which connects the output of one program into the input into another. - Proc: A file that gains access to (and in some cases, change) the kernal data itself
3.1 Hardware:
/dev/[name] - device directory
3.2 Terminal:
/dev/tty[#] - terminal /dev/pts/0 or, /dev/ttyp0 - Pseudo terminal
3.3 Pseudo Devices:
/dev/null - discard output, input returns nothing
/dev/zero - discard output, input returns nulls(this is important, sometimes you gotta send somethin!)
/dev/random - random number generator, has some redunduncy
/dev/urandom - random number generator, can be slow from having to collect noise
3.4 Pipe Files:
File output | file input the | key is a command for a single instance pipe.
mkfifo - fifo satands for file input/ file output - use to maked named pipes
Anonymous vs. NAMED - Named pipes continue to exist until deleted, anonymous pipes are single instance commands.
3.5 Proc Files
ls -l /proc/kcore - wanna see the memory of your system!?
_Mounting Vs. Unmounting_
Every storage device has its own directories and subdirectories, in order to connect two more devices, the smaller device root need to be connected
to a specific directory in the parent device. The Connection is called a MOUNT. The directory that the smaller filesystem is located in the parent
device is called the MOUNT POINT.
mount [device directory] [main tree directory location] - mounts a device manually
the device directory is the root of the device itself, whereas the main tree directory is where access to that devices directories on the system.
- the main tree directory has 2 types fixed, and removeable. the fixed is used for titems like hard drives and other coponants that will be
permanently attached to the computer. removeable are things like CD's Flash drives etc.
/mnt - the fixed mount directory
/media - the removeable mount directory
umount - unmounts a device manually
_/bin_ - this holds commands!
df -(stands for disc filesysyems) lists all partitions, the memory allocated for certain key storage programs, lists amount of allocated memory that is in use, the location of the partion, and keeps that allocated memory from being accessed by everyone, so that only certain people with access can modify or access that memory.
groups - all the groups your user is a part of.
ls -l - this lists a bunch of stuff about the directory you're in.
- 1.lists the read (r), Write(w), and execute(x) access to files, in three groups of the user, the group, and other, otherwise known as the UGO. - 2.number of links to the file - 3.Owner of the file - 4.What group the file belongs to - 5.the size of the file in bytes. - 6.The month the file was created. - 7.The day the file was created. - 8.the time the file was created. - 9.the name of the file
chmod [(UGO) (+/-) (RWX access)][name of file changing] - Change mode - This allows you to put a file or directory in a shield, or protect it so that only users with access can change its memory.
the first argument states whether you are giving the user(U), Group(G), or everyone else or other(O), read®, write(w), or execute(x) access. you give them RWX access with a + sign and take away RWX access with a - sign
If one were to want to give the same RWX access to UGO, one could use a instead, for All
multiple commands to RWX and UGO can be done simultaneously with a comma:
User with RWX access and Other with only RX access:chmod U+RWX,O+RX
This can also be done with a numeric value, with read = 4, write = 2, execute = 1, none = 0. With each user in the UGO getting a numeric value for each RWX group.
for the user to get all access, it would add to 7, or RWX 4+2+1,for read and execute it would be 5, or RX 4+1, and so on and so forth.
for this mod, a number must be assigned for each UGO group, otherwise it will only modify the other group, and erase the other user and groups RWX access.
IE: chmod 777 [filename] - gives RWX access to all UGO users. chmod 666 [filename] - gives RW access to all UGO users. etc…….
- - Plain File d - Directory l - Link p - Pipe b - Block Device c - Character Device
links are copies of files that span file system. ln [file 1][file 2]
To copy the files in the archives folder:
cp archive1.tar.gz ~
This copies the file and puts it into the home directory ~
Repeat for archive2.zip
To extract archive1.tar.gz ,
first, you gotta go to your home directory to access write access to your copied files.
cd ~
second
tar -zxvf archive.tar.gz (I had to look this up on them there internets to find all the options to decompress)
to decompress that shiz
third to unzip archive2
unzip archive2.zip
tar -cf arc.tar filea fileb filec filez
-c creates the compression f creates the file
gzip –best filea fileb filec filez
from the path /src/unix/badname:
chmod 777 -R exercise
this gives write and read access to errryone.
nano just\ a\ simple\ file.txt
rm “??? can you delete me ???.abc”
mv “change my\ name.file” No_I_Will_Not.file
and so forth
rm ./“- challenge round -“
then type yes and enter
less, more, pg, cat
Others for specific parts of a file instead of a whole file.
Head For the head of a file
tail to display the end of a file
grep
a pager is a command that displays the contents of a file.
less (name of file)
(to see more about less refer to pages 527 through 535 of Hahns )
You can edit the pager your system uses by default when a program calls the Pager program for display. this is done by:
Bash:
export PAGER= then put in the pager you would prfer to use, primarily is is less so it would be export PAGER=less
C-Shell:
setenv PAGER less
= =
Commands:
:n change to next file in list
:p change to previous file in list
:x change to first file in list
:e insert a new file into the list
:d delete current file from list
:f display name of current file (same as =)
=same as :f
/* (pattern) - search forward for a specified pattern
?* (pattern) - search backward for a specified pattern
vi be a text editor
vi -R - Read only mode! to keeo you from changing important stuffssss
hexdump -C (command path) | (command) - displays command in canonical format
od -Ax -txlz (command path) | (command) - displays command in canonical format
= =
-A - address
x - canonical output
-t - type of format
x1 - display canonical format
z - display in hex one byte at a time
-j (bytes ie:0x120) - jump over bytes declared
-N (bytes ie:96) - Limit output to bytes
these display binary data.
Also, Learn how to count in multiple number systems, DO IT.
whereis (command) - displays the path to the location of a command
The Shell - The Shell is a User interface and script interpretter. or a COMMAND PROCESSOR
sh- Enter shell, start work session, enter commands, shell processes commands and then sends a new shell prompt. the Bourne shell eventually adapted the standard title in 1975
ksh - the KORN Shell - an inprovement to the sh Bourne capabilities
bash - The free shell devolped by users for the a$h-Holes at AT&T
csh - A shell based off and expanded from the original sh shell, but expanded with major improvements like aliases. was also created by Bill Joy, ans he's awesome, because he made vi
tcsh - the free version of csh developed by ken greer.
the Bourne Family Shells were better at programming and shell scripts, so C-Shells got phased out of use.
Hahns found it pertinent to state that C-Shells are not widely used, but highly regarded, and that Bourne Shells are better, but then goes on how to use them. I don't find this important
There are many different types of shells and the commands for them may alias other versions, but this isn't entirely imporant for beginers.
open command: sh - may open bash or ksh shells
open command: csh - may open tcsh by default
ssh - Secure Shell
rsh - remote Shell
Changing to a different shell
= =
Shells are treated just like any other program, your operating system just has a default in which it is set to.
In order for you to try another shell, you just have to type the name of the shell as a command, then the system will pause the default shell, and open the shell you had commanded to open.
IE: If you have a default shell of bash and you would like to open tcsh you just type and execute the tcsh command and use ^D to exit the tcsh program.
'less(or any other text editor) /etc/shells'
or
'chsh [-1]
Changing Shells: chsh or passwd
=Howto:=
you can change your login shell you use the chsh command which functions with 2 parameters and options
chsh [-s shell] [userid]
Display Current Shell: echo $shell
Names and types of terminals being used: TERM, xterm, linux, vt100, ansi;
There are only 4 ways in which to interact with variables: Create, Check Value, Change Value, and Destroy
Two types of variables are Local and Global
Local - variables that are located and only have a scope of influence in the place in which they are created.
Global - Variables that are located in one place, but have a scope that is wider than simply in the place they are created.
env - Display the default Environment variables.
printenv - display default variables.
Use less - to display one page at a time of environment variables
use sort to display variables in alphabetical order
IE: env | sort | less This is a pipeline command. It implements many commands at once.
set - display all shell variables
echo ${Terminal Type} - display a single shell variable.
IE: echo $TERM
Use all caps with a equal sign after, this creates a shell+environment variable(in Bourne Shells).
non bourne families - in other shell families, the export [VARIABLE] command needs to be used to make a created variable both shell and environment variables.
one could also use an expression to create and declare a variable to environment:
VARIABLENAME=variablecontent ; export VARIABLENAME
unset VARIABLENAME VARIABLENAMEetc…
The C-Shell Family has a more clear distinction from global and envirionment variables than the borne shell family, the bourne shell family only has shell(local) variable and combination variables that are both shell(local) and environmental(global). The C-shell family uses unique Environment(global) variables. As such there are different commands for these shells.
To set(create) and unset(delete) shell variables the set and unset commands are used. To create and delete environment variables the setenv and unsetenv commands.
If you create a variable without giving it content, it will be set to NULL
Shell options are that in which control the operation of the shell.
set -o - Displays all shell options
set +o - Displays shell options data to be used in a script
send either to less to display in an easier manner to read.
- For you to change your shell, you have to have the other shell in the /etc/shells directory, and you can only change your user id settings, you cannot change another users shell setting unless you are a superuser(The Sayian of Users).
-some systems don't have a chsh command so passwd is used with the [-s] option on AIX, and the [-e] on solaris.
As System Administrator, the way to change someone else's shell is to use usermod with the option[-s](see man for more implementation)
Metacharacters are characters that have special meanings and functionality that is specific to the shell.
Because there are so many damned metacharacters for specific uses, it would be redundant to list them here, it would be like trying to list all theo words in the dictionary. At some point, from using them, it will become apperent what should be used when.
I will just describe the ones used as they are mentioned in this and the upcoming chapters. A few of which have already been explained, but not as that they are metacharacters.
sometimes it is pertinent to print a metacharacter and not have it be enacted by the shell, for viewing and explaining purposes, there are a few ways in which to do this.
placing a \ before a metacharacter in a sentence will nullify it from being enacted by the shell
echo mike wizowski \; you didn't fill out your paperwork
The ; in this instance has been ketp from enacting by the \ character
This implies that the \ is an escape character, in that it changes the mode the shell interprets the following character.
The \ is good for single characters, but it can get tedious for multiple characters you wish to escape, in that instance, there are other ways to escape from other metacharacters.
echo 'mike wizowski; you didn't fill out your paperwork'
by encasing the entire statement after echo it escapes all metacharacters that ly within them.
The double quote is used to escape displaying metacharacters, but for variables that can output a value, it does not escape the $ character and the variable name, so that the value of that variable can be displayed.
echo “mike wizowski; you didn't fill out your paperwork, <$TERM>“
This will print the value of <$TERM>, while escaping the ; character within the quotes.
the double quote only recognizes 3 characters to not escape:
1.$ - Value
2.`(backquote)
3.\ - specific character escape
When a Command is enteres the shell breaks it apart into sections, or parses it.
It breaks it into the
1.name
and
2.Arguments/options
of each command.
When a command is BUILTIN, it is run directly by the shell within its own process.
When a Command is EXTERNAL, the shell searches for a specific program and runs it in a seperate process.
type [command]:
type is a command that will output the path to EXTERNAL Commands, and state whether or not if the command is a shell command, also called a BUILTIN command or KEYWORD(specific for shell scripts).
The man [command] pages work well for external commands for viewing, however, one cannot view BUILTIN commands because they are not seperate programs, they are within the shell program.
To do this you need to view the man page for the shell itself
so it would be:
man bash:
(or whatever shell you are using)
Other systems have seperate man pages for their BUILTIN commands, but this is system dependendat.
to tell whether or not this is the case for your system use:
apropos builtin
Which will print the place in which the commands are held.
Because EXTERNAL Commands are not enacted directly by the shell itself, it has to find and execute them seperately.
It does this by searching a standard PATH search within the /bin or /usr/bin directories, or something along those lines, to find and execute those commands.
the PATH variable is the where the shell searches for external commands. In most circumstances this is set for you in default places, however, sometimes it is necessary to declare the PATH for the shell to find a command that is not in a standard /bin directory.
the extort command allows for the PATH(or path in C-shell families) variable to become an EXTERNAL variable, and then that variables' content needs to be set for the PATH to be set to the right directory.
export PATH=”/bin:usr/bin:/usr/ucb:/usr/local/bin”
(in C-Shell Family the set path= [path] command is used for the same result)
Reasoning
Sometimes Shiz just aint where it ought to be, or its where it ought to be, and ya'll gotta go find it, and let the machine know where it is for it do to its shiz.
Kinda hard to take a shiz when you don't know where the bathroom is!
Say you write a shell script, that has its own /bin directory($HOME/bin), you would want the shell to enact those commands and the PATH of $HOME would needed to be changed in order for the shell to find those commands.
IE
export PATH=“$HOME/bin:$PATH”
This changes the value of PATH to the value of $HOME in the /bin directory of the EXTERNAL of HOME, allowing your script to find its shiz.
the :$PATH at the end makes it so the PATH still retains its standard searching directories as well, instead of completely erasing the standard PATH and replacing it with HOME/bin.
By putting HOME/bin in the front it allows the HOME/bin directory to be searched for commands first, by putting it at the end it does the oppisite.
if you do this you will be HACKED and you probably deserve it as well.
by implementing the root into the PATH you open yourself up to allow other people to access everything on your system without needing a password. DON'T Do it
$ - Bourne Shell Fanily
% - C-Shell
> - Tcsh
# - root on either shell system
The Bourne shell family has an EXTERNAL variable named PS1 that holds the value of the prompt. Because it is an EXTERNAL variable it can be set eith the export in Bourne shells and set in C-Shells.
Bourne:
export PS1=“$ “
C-Shell
set prompt = ”> “ or, set prompt = ”% “
COMMAND SUBSTITUTION = This Embeds one command with another, executing an embedded command and then replaces it by its output.
The `(Backquote) character tells the shell to execute commands in 2 parts.
What it's doing:
it evaluates date first due to the ` (backquote), and replaces its value into the space within the backquotes, and then continues to evaluate the rest of the command.
so if the date were Monday April 5th 3013 at 8 am the command would read:
echo “the time and date are Mon Apr 5 08:00:00 EST 3013”
which would then just print:
the time and date are Mon Apr 5 08:00:00 EST 3013
the history list is the list of commands that have been sent to the shell.
fc stands for “fix command
other options allow you to execute members of the list such as:
fc -s [command number within list]
to execute members of the list:
![number on list]
the list size is the amount of commands that are saved into the history value
this can be changed using the variable:
and can be set with the export(or set in C-Shell) command:
export HISTSIZE=[size you wish to save]
Initialization files are that in which customize your shell and be executed automatically upon your behalf.
Environment files are the files in which you put all the commands you wish to be executed everytime a new shell starts and Login files for everytime you log in.
yo fool? got a shell script that needs to be POSIX compatible?
Start it with the –posix option. so it'd be bash –posix
Dotfiles are hidden files
rc files are initialization files for their encompassing named programms/commands.
which is the initialization file for the vi and ex text editors.
.bash_login
.bashrc
This is a sample format for a dated entry. Please substitute the actual date for “Month Day, Year”, and duplicate the level 4 heading to make additional entries.
As an aid, feel free to use the following questions to help you generate content for your entries: