Nicholas Vitulli's fall2014 Opus
A journey in UNIX
My name is Nicholas Vitulli and I am a CNC Machine Operator with Synthes. I have a B.S. in Architectural Technology from Alfred State College and am currently pursuing a A.S. in Computer Science from Corning Community College. Prior to going to college I served in the Army. My plan is to move on to a B.S. in either Computer Engineering or Software Engineering.
In the first week of class I was introduced to Linux. This has been my first direct experience with the system. In class we have covered several commands such as who and w. We have also covered opening a chat window using the screen, irssi, and server commands. Concepts covered in this week of class have included “The Unix Philosophy”, “3 Types of Files”, and “Access Control”. I found access control to be a little confusing at first but after playing with it for a wile it made a lot more sense. Outside of class I have read the first 3 chapters of “Unix for the Beginning Mage”.
In the 2nd week of class I set up my repository and learned how to push and pull from it. In class we learned about relative and absolute paths. We learned several commands including ctrl c, cat, and echo to name a few. We went over redirects. Note: check email weekly for possible extra credit.
In week 3 we continued to explore the folders we have access to. We were introduced to some cool tools like alpine, cal, date, and pon. Another tool we explored was messaging between two users on the same system. This week we also took a look at our first project and discussed the concepts of Archive and Compression. The climax of this week was vi (visual editor). This is the first time I have ever used an editor where there is a command mode and insert mode. It has taken some getting use to but once familiar I could see how this editor would improve productivity.
In week four we did some more work with Vi exploring the copy command and move. We also looked at searching for regular expressions. Vi is becoming more familiar and easier for me to use. Two important commands to remeber for class are submit unix and status unix.
In week five we learned about the very useful Super Mario Bros. pipe, well maybe it was a unix pipe. this great tool take output from one command and pipes it into input of the next command. We also learned about the head and tail command, as well as the different types of quotes within unix. The highlight of the week was a toss up between the puzzle box project and dinosaurs with hats.
ls -l /bin/ls
process - a program in action
PID = Process identification #
16 bit number = 2^16 = 65536
ps - report a snapshot of the current processes
run cat - in one terminal and run ps in the other to see cat - PID
kill - send a signal to a program
kill -l - this list the ways to kill a program
kill -1 PID - PID is the number of the process
you can not stop a sigkill
ps aux | grep $USER - displays all processes being run by the user
top - displays Linux processes
shell - a user interface
sh - bourne shell bash - bourn again shell BSD csh - C shell
ctrl z stops a process and can be resumed later
bg - puts a process in the back ground fg - fore ground
Knowledge assessment next Thursday
echo $RANDOM = spits out a semi-random number
%Modulus = the remainder when dividing numbers ex. 34 % 5 = 4
/Division = the whole number when dividing numbers ex. 34 / 5 = 6
when moding the remainder will not exceed the divisor. ie 5
- echo $(($RANDOM100%)) this produces a number 0 through 99 - echo $((($RANDOM100%)+1)) this produces a number 1 through 100
1 #!/bin/bash 2 choice=$((($RANDOM%100)+1)) 3 guess=0 4 while [ "$guess" -lt 6 ];do 5 echo -n "Guess a number: " 6 read number 7 if [ "$number" -eq "$choice" ];then 8 echo "Bam, you got it, hot diggity dog" 9 exit 0 10 elif [ "$number" -lt "$choice" ]; then 11 echo "Highter" 12 else 13 echo "Lower" 14 fi 15 let guess=$guess+1 16 done
answer=`echo “2+2” | bc` echo $answer
1 #!/bin/bash 2 total=0 3 evens=0 4 for number in `cat datafile.txt`; do 5 evencheck=`echo "$number%2" | bc` 6 if [ "$evencheck" -eq 0 ]; then 7 let evens=$evens+1 8 fi 9 let total=$total+1 10 done 11 echo "Out of $total numbers, there are $evens even numbers" 12 exit 0
Project Status Script
1 #!/bin/bash 2 opusT=`status unix | grep opus | wc -l` 3 opusP=0 4 opusS=`status unix | grep opus | cut -c5 > opusS` 5 for number in `cat opusS`; do 6 opusP=`echo "$number"+"$opusP" | bc` 7 done 8 echo "Out of $opusT possible points you have earned $opusP" 9 exit 0
echo "$(echo "(6/7)*100" | bc -l | cut -c1-5)%"
85.71%
status unix | grep "$USER" | tr ' ' '\n' | grep -v '^$' | grep -v "$USER" | wc -w status unix | grep UNIX | tr ' ' '\n' | grep -v '^$' | grep -v UNIX | wc -w
what can a regular expression(RegEx) do for you?
cd /usr/share/dict cat words | grep 'REGEX' | wc -l cat words | grep '^....$' | wc -l * This matches start of line followed by four characters followed by end of line cat words | grep '...g$' | wc -l cat words | grep '^....*g$' * These matches four or more characters with the last one being a g cat words | grep '^[a-z][a-z][a-z][a-z]*$' | wc -l * This matches words with three or more lower case letters cat words | grep '.*[aeiouy].*[aeiouy].*[aeiouy]' | wc -l * this matches words with three or more vowels cat words | egrep 'REGEX' * egrep turns on the extended regular expressions cat words | egrep '[e][d]$|[i][n][g]$' | wc -l cat words | egrep '(ed$|ing$) | wc -l * these matches words ending in ed or ing
More Regular Expressions
status unix | grep 'opus' | grep '[02468]entry$'
This prints even days of the opus
Lets get ready to sed
status unix | grep 'opus' | sed 's/^.*\([01]\):\([a-z][a-z]*\):\(week\)\([0-9]\)\(.*\)$/\5 for \3 \4 \2 [\1]/g'
This out puts entry for week # opus [#]
getent passwd | sed 's/^\([a-z][a-z]*\):x:\([0-9][0-9]*\):\([0-9][0-9]*\):\([NBV][a-z]*\)/\4/g'
Some new tools
output.txt # this would save the output from the status unix command in output.txt status unix > ~/tmp/output.txt rm -f output.txt # puts the file in a tmp folder and then delets when done stat ouput.txt | grep Modify | sed 's/^Modify: //g' date -d "$(stat output.txt | grep Modify | sed 's/^Modify: //g')" +%s # how old the file is in sec from the start of time ftime=`date -d "$(stat output.txt | grep Modify | sed 's/^Modify: //g')" +%s` # saves the time in a file called ftime ctime=`date +%s` let dtime=$ctime-$ftime echo $dtime time command # shows the amount of time to run the command at 531pm # runs the command at 531pm cron/crontab
scheduling stuff
#at is a one time run and crontab is a reoccurring run at 16:16 ls > out # runs the ls command at 16:16 and saves it to out crontab -e # edit the crontab */4 * * * * /usr/bin/who # emails the result of who every 4 min # last - displays every time every one logged in last | grep nvitull1 | wc -l #counts the number of time I have logged in # better to use "$USER" instead of nvitull1
A new project - cue the parade
-accept via commandline argument, or user input if no arg, the desired user name to process -verify that its a valid user, proced only if valid -for each month of the semester determine number of loggins and total amount of time in days hours min -total loggins for semester, total time for semester -histogram
last - list all the loggons lastlog - list the last log on of each user
Work on stuff day
The begging of the End!!!
A Palindrome is a word or phrase that is the same forward as backward. like “taco cat”
status unix | sed -n '/^PROJECTS$/ {s///; :a; n; p; ba; }' | sed -n '/SUBMISSION REPORT/q;p' | sed 's/^.*\([01]\).*/\1/g'
This will print everything after PROJECTS
The biggest problem I encountered during the archive project was figuring out how to transfer the files from the server to my laptop. I ended up using the pscp command in the windows command prompt. Creating the archive and compressing it seemed straight forward. I like that the two can be separate that way you can create and archive without compressing it just to keep the files together. Also you can compress a single file without having to archive it.
who - shows who is logged on
who [option] [file | arg1 arg2 ]
ls - list directory contents
ls [option] [file] -l use long list format
chmod - change file mode bits
chmod [option] mode[mode]... file... x - 1 w - 2 r - 4
ctrl c - to quite out of a command
cat - concatenate files and print on the standard output
cat [option] [file]
echo - display a line of text
echo [option] [string]
set - set or unset values of shell options and positional parameters
set UID - sets user ID set GID - sets group ID
alpine - email service
cd - change directory
status unix - check attendance and grades for unix course
cal - calender
man [command] - manual page for command entered
date - current time and date
ncal - calendar and date of Easter
pom - phase of the moon
write - send a message to another user
write user [ttyname]
tar - saves many files together into a single tape or disk archive, and can restore individual files from the archive
tar [option] [file] -cf - create archive -xf - extract archive -z - gzip archive
gzip - compress or expand files
gzip [option] [name] -1 though 9 - fast though best -d - decompress
vi/vim - programmers text editors
i - insert mode esc - command mode
wc - print newline, word, and byte counts for each line
head - output the first part of files
head [option] [file] -c - print the first K bytes of each file -n - print the first K lines of each file
tail - output the last part of files
file [option] [file]
sort - sort lines of text files
sort [option] [file]
getent - get entries from Name Service Switch libraries
getent database [key] getent passwd
bc - calculator
obase - Hex base ctrl D - breaks out to prompt
groups - shows which groups you belong to
grep - print lines matching a pattern
grep [options] pattern [file]
cut - remove sections from each line of files
cut option [file] -b - select only these bytes -c select only these characters -f select only these fields
uniq - report or omit repeated lines
uniq [option] [input [output]] -c - count -d - only print duplicate lines
tr - translate or delete characters
tr [option] set1 [set2]
file - determine file type
ps - report a snapshot of the current processes
printf - formatted output conversion
alias - define or display aliases