Table of Contents

UNIX class notes

In Depth VI Notes

Basic VI Notes

REGEX's

Week 1

Welcome to the best class you have ever taken

This page includes some notes, typically major things, from each class session

Please add notes whenever you can = )

Week 2

*Re-went over group and pwd command

*we went into the /bin folder and found we can find new commands to play with

*we spoke about kernels, the foundation of the operating system. the kernel is what boots the operating system

*we went into other root folders, the dev folder contains many special files such as the zero file, which, similarly to the yes command, spits and endless string of 0's

*talked about full and null, check man files

*used the watch command, it repeats the following command with a delay ie, watch ls repeats ls continuously until exited

*you can check your messaging status with mesg

*to change messaging status follow mesg with y, or n depending on how you wish to change it

*went into /etc and checked out the passwd and shadow files, had a conversation about encryption

*we explored the group file in /etc

*we went into the /lib directory

*used ldd command, shows what libraries are needed for given argument

*went into the /proc directory, one thing in there is the cpuinfo file, which can show the hardware info from far away

*went into the /var directory

*/var/public is where projects are found when not using grabit

*went into /usr and subdirectories within


Week 3


Tuesday

Wildcards are a set of symbols that can be used to match files or directories. The four main wildcard symbols are: ?, *, [], [^]. The '?' symbol matches any single character, the '*' symbol represents 0 or more characters, the '[ ]' symbol represents a range of values, and the [^] symbol will exclude the range of values inside.

Wildcard examples:

ls -1d ??? This lists all files that contain only three letters in their name.

ls -1d c*n” This lists all files that start with a c and end with an n but has any combo of characters in the middle.

ls -1d ?[aeiou]??” This lists all four-letter files, but the second letter must be a vowel.

ls -1d ?[^a-j]?” This lists all three-letter files, but the second character must exclude all letters ranging from a through j. As you can see, you can represent a range of values either using a dash or entering the specific characters inside when using the '[]' or '[^]' symbols.

You can also “wc -l” to find how many files fit the criteria of your wildcard symbols.

For example: “ls -1d ?[d-m]?? | wc -l

Thursday

File permissions get more complex, you can now have s, S, t, and T covering the x in each category user and group execute permission would be replaced with s or S, other execute permissions can be replaced with T, or t. If it is capital there is no execute permission, if it is lowercase there is an execute permission s in user is setUID, s in group is setGID, t is other is sticky the new categories numbers are added on the front, so -rwSr-s–t implies user has read and write, no execute and it has setUID, group has read, execute and setGID, other has execute and sticky s (user) is 4, s (group) is 2, t (other) is sticky, so the previous example would be 7651, 7 because it has Sst, 651, because afformentioned basic permissions in unix double quotes are called half quotes, they allow expansion in unix single quotes are called full quotes/literal quotes, they have no expansion backtick is called a command expansion a word preceded by a dollar sign is a variable typically environment variables are in all caps backslash toggles functionality of the next character, ie /$varname does not call the variable


Week 5


Tuesday

The first portion of class was focused on different number bases, and solving our first octal pct. We went over what next week's projects will be, tpb0 and gfo0. We started using Vi in class which is like the original version of Vim (vi improved). Vi is a bi-moded text editor (meaning that there is a distinction between putting text in and running commands), and some text editors like Notepad and nano are unimoded text editors (meaning that there is no distinction between putting text in and running commands). Vi has command mode and insert mode, it starts in command mode

Insert commands (put you in insert mode):

To get out of insert mode press the esc key

Navigation commands:

(prefixing the navigation commands with a number moves by the number of characters, ie 6h moves left 6 characters) If you want to open Vim on a certain line you can type vim +line# textfilename

i.e. vim +57 project.c

Manipulation commands:

Exit commands

You can see why vi is bimoded because we can switch between two different modes (command and insert).

Thursday

More basics in Vi

–Extended VI command mode–

to enter type a colon :

You can edit your default settings in Vim by adding to your ~/.vimrc file ie by adding colorscheme torte to your ~/.vimrc file it changes the default colorscheme

–Other stuff– In unix the date command tells you the date and time, you can also specify dates, you can format the data, check the man page for further use

You can use cal to show a calendar, you can specify month and year ncal shows the calendar in a different orientation

head gives you the lines from the top of the file ie head -3 gives the first 3 lines tail gives you the lines from the bottom of the file ie tail -5 gives you the last 5 lines sed can do a search and replace


Week 6


Tuesday

whereis command shows the path to the executable given, ie whereis who responds with /usr/bin/who

for loops in bash may look like:

for VARIABLE in list OR command OR anothervariable; do
    something that the loop is doing;
done

ie

LIST=$(command that gives us some list)
for user in ${LIST}; do
whatever we want to do with the list;
done

Thursday


It is good practice to begin your scripts with #!path to interpreter so for our shell scripts, if we are using bash it would be useful to begin the script with #!/usr/bin/env bash

if statements in bash look like

if [ Condition to check ]; then
whatever we are doing
fi

numeric for loops

for (index=somenumber; index > OR < some other thing; )

in VI shift » and « change the indents by one level

Week 7


Tuesday

We did our first base 9 puzzle

More modification to our script, now it lists out time in days, hours and minutes

The script now accepts arguments to sort by most logins or most time

There are many ways to pass a script an argument, the way we did is by giving a variable the arguments defined by ${#}, ie the first argument would be ${1}

Thursday


The dawn of the final puzzle box is upon us, enjoy its brain expanding power

Field trip, went to the binary clock, which runs on an older gen raspberry pi

We found multiple ways to reset/backup an sd card

Field trip resulted in many great discussions pertaining to engineering and the limitations of creating technology, including software

Week 8


Tuesday

No class, free day for experimentation/completing assignments

Thursday


No class, free day for experimentation/completing assignments

Week 9


Tuesday

Virtual class session day

Started discussing wpa0

in a man page, or vi, or a less pager you can use a forward slash to search for something

Remember wildcards are specifically filenames, regex's are for text

REGULAR EXPRESSIONS!!!!!!!

Basic REGEX (in Unix)

Extended REGEX

3 types of grep used to be used based on what REGEX's you need

you can still use extended regex with a regular grep, but they need to be preceded by a \, ie a grep “\?” should work like egrep “?”

diff - a command that can show differences in files, assuming they are sorted

Thursday


No class, free day to experiment and work on projects

Weeks 10-14


Mostly given time to work on projects, the last major discussion was Regex's, and a quick base 11 pct Work on your EoCE

Cleaned VI Notes

(Images courtesy of Corey)


There currently is more above, check Week 5 for a more complete list