Michael Gleason's fall2014 Opus
Sweg
My name is Michael Gleason, I enjoy soccer and working with computers. I'm Japanese and German. I like playing League of Legends and deleting AmazingAsian (Julian Cliteur). I like food and sleep. I eat a lot and sleep a lot. I plan on becoming a pilot and to further my education in computer engineering.
% Modulus / Division 34 % 5 = 4 34 / 5 = 6 Modulus is the remainder. echo ‘ ‘ $( ) $(( )) echo $(($RANDOM%100)) values 0-99 echo $(($RANDOM%100)+1)) values 1-100
#!/bin/bash choice=$((($RANDOM%100)+1)) guess=0 while [ ”$guess” -lt 6 ];do echo -n “Guess a number:” read number if [ “$number” -eq “$choice” ]; then echo “You have correct now” exit 0 elif [ “$number” -lt “$choice” ]; then echo “Higher” else echo “Lower” fi let guess=$guess+1 done exit 0
cat data | grep ‘2’ | wc -l bc = binary calculator obase=16 quit answer=’echo “2+2” | bc’ echo $answer
#!/bin/bash total=0 evens=0 for number in `cat data`; do evenchk=`echo "$number%2"|bc` if [ "$evenchk" -eq 0 ]; then let evens=$evens+1 fi let total=$total+1 done echo "Out of $total numbers, there are $evens even numbers." exit 0
<codebash> echo “6/7” | bc -l echo “(6/7)*100” | bc -l go to man bc* echo “(6/7)*100” | bc -l | cut -d`.` -f1 echo “$(echo ”(6/7)*100“ | bc -l | cut -c1-5)%” </code>
attendance - username status unix | grep mgleaso7
Only one “Enter” at the end. status unix | grep mgleaso7 | tr -s ' ' '\n' ^ new line $ end of a line grep -v ‘^$”
missed=$(status unix | grep mgleaso7 | tr -s ' ' '\n' | grep X | wc -l)
? - match any single char [ ] - character class. match any one of the enclosed characters. *- match 0 or more of anything inverted character class
. - match any single character * - 0 or more of the previous char class [^ ] - do not match one of the enclosed \< - match start of word \> - match end of word ^ - match start of line $ - match end of line
| or ( ) grouping → \( \) + - match one or more of the previous.
<codebash> cat words | grep '^[a-z][a-z][a-z][a-z]*$' | wc -l
cat words | grep '^.*[aeiouy].*[aeiouy].*[aeoiouy].*$' |wc -l
ccat words | egrep '(ed)$|(ing)$' | wc -l </code>
egrep = grep + moar fgrep = fast grep, no regex
<codebash>
status unix | grep ‘opus’ | grep ‘week[02468]’
egrep ‘week([02468] | [0-9] [02468] )’
1 : opus : week2entry
sed ‘s/ |
getent passwd | grep '^[mg]' | sed 's/^\([a-z][a-z0-9]*\):x:\([0-9][0-9][0-9][0-9]\):5000:\(.*\):\/home.*$/\3 is user \1 with userid \2 /g' </code>
*/4 /usr/bin/who where is status
at commands
at - executes command at specified time
atrm - deletes job by job number
at 16:16 - sets command at 4:16 Linux time
ls > out - command that will run at 4:16
atq - shows the list of commands that you set to run
crontab -e - lets you choose an editor to create a repeating command
*/4 * * * * /usr/bin/who - runs that command every 4 minutes of every hour, day, week, month
After a successful crontab command it should say: crontab: installing new crontab
last - shows when a user logged in
last | grep $USER | wc -l - shows how many times you logged in
last | grep $USER| grep Oct | wc -l - shows how many times you logged in October