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