User Tools

Site Tools


opus:spring2012:thakes3:unixpart3

unix Keywords

Regular Expressions

Like pattern matching, regular expressions involve text manipulation and other commands like grep.

Definition

By definition, a regular expression is a formula for matching strings that follow some pattern.

Demonstration

Networking, Unix tools

There are several important commands in unix for networking. Whether it's checking your IP address or seeing if a website is up, these simple networking tools are very important.

Demonstration

ping - it sends packets to the address you give it, and tells you whether or not it received them.

lab46:~$ ping cnn.com
PING cnn.com (157.166.255.19) 56(84) bytes of data.

ifconfig - device interface config. These are your networking devices and what they are currently up too. It will list a bit of information reguarding the network it is connected too.

[sudo] password for thakes3: 
eth0      Link encap:Ethernet  HWaddr 00:30:84:0e:88:c1  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:16 Base address:0x1400 

eth1      Link encap:Ethernet  HWaddr 00:11:0a:36:64:4d  
          inet addr:10.80.2.180  Bcast:10.80.2.255  Mask:255.255.255.0
          inet6 addr: fe80::211:aff:fe36:644d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4832 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2954 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:4155503 (3.9 MiB)  TX bytes:526011 (513.6 KiB)
          Interrupt:20 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:10 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:660 (660.0 B)  TX bytes:660 (660.0 B)

Telnet - a protocol that allows you to remote to computers and both receive and send ascii text.

one of my favorite Telnets would be the star wars movie in ascii.

telnet towel.blinkenlights.nl

Shell Scripting

Shell scripting in unix is very important as it accomplishes repetitive tasks simply and provides an easy method of executing a command that takes rather long to type over and over again.

Demonstration

Shell scripting is very useful for writing a long command that sometimes is forgotten.

For this demonstration I will reveal my ssh shell script within my home folder

lab46:~$ cat Universe
ssh thakes3@69.207.208.154
lab46:~$

by changing the permissions to allow it to be executed (chmod a+x Universe) all I would need to do is execute that file and it would ssh me to that address.

lab46:~$ ./Universe
thakes3@69.207.208.154's password:

Security

The security environment in unix is rather unique as it relies on permissions and users to block out the information that should not be accessed by others.

Demonstration

Permissions are important in unix as they are needed for the current user to access the file. If your permissions are low for other users, such as read only, then they are not able to edit the file or make amends to it.

to view your permissions, use the -l appendage to the command 'ls'

lab46:~$ ls -l
total 3
drwxr-xr-x 4 thakes3 lab46 46 Feb 29 11:41 Backups
drwxr-xr-x 2 thakes3 lab46 28 Feb 25 15:06 Desktop
-rwxr--r-- 1 thakes3 lab46 27 Mar 2  14:43 Foxtrot
lab46:~$

to edit your permissions, see the chmod command.

Users in Unix often are put within a group of other users often referred to as a User Group. They are often given certain permissions to the entire group so that the group can accomplish a task together. every user must be a member of at least one group, which is identified in /etc/passwd. This group is referred to as the primary group ID. A user may be listed as member of additional groups in the relevant entries in the /etc/group; the IDs of these groups are referred to as supplementary group IDs.

results given by cat'ing /etc/group :

lab46:~$ cat /etc/group
root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:
tty:x:5:wedge
disk:x:6:
lp:x:7:
mail:x:8:
news:x:9:
uucp:x:10:
man:x:12:
proxy:x:13:
kmem:x:15:
dialout:x:20:
fax:x:21:
voice:x:22:
cdrom:x:24:
floppy:x:25:
tape:x:26:
sudo:x:27:
audio:x:29:
dip:x:30:
www-data:x:33:
backup:x:34:
operator:x:37:
list:x:38:
irc:x:39:
src:x:40:
gnats:x:41:
shadow:x:42:
utmp:x:43:
video:x:44:
sasl:x:45:
plugdev:x:46:
staff:x:50:wedge
games:x:60:
users:x:100:
nogroup:x:65534:
libuuid:x:101:
crontab:x:102:
ssh:x:103:
ntp:x:104:
tss:x:105:
scanner:x:106:
nvram:x:107:
fuse:x:108:
kvm:x:109:
rdma:x:110:
messagebus:x:111:
utempter:x:112:
avahi:x:113:
netdev:x:114:
cl-builder:x:115:

$PATH

The path variable in unix is used for finding files that are executable instead of having to go to those locations specified inorder to execute a program.

Demonstration

By echo'ing the $PATH variable, you are given each directory that the cli searches for on the system.

lab46:~$ echo $PATH
/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
lab46:~$

without these listed, when you attempt to use a program it will return a “command not found”

lab46:~$ PATH = null
lab46:~$ man dd
man: command not found
lab46:~$

Tab Completion

Tab completion in unix refers to the utility that allows you to automatically fill out the rest of the command you are attempting to type out, as well as directories that exist.

Demonstration

By using Tab completion your computer will guess as to what you are attempting to type. Let's say I want it to auto complete for file.

lab46:~$ fli
file               filebyproc.d       filecoordinationd  filtercalltree
lab46:~$ fli

Now I would like to edit a file with a very long file name. lets say treehuggersarefriendly.txt . Since there are no other commands or files that have any characters beyond tree, it will auto complete the name for you.

lab46:~$ vi treehuggersarefriendly.txt
lab46:~$

Environment Variables

Environment Variables are sets of dynamically named values that affect how programs run.

Demonstration

By using the command 'set', you are able to see all of the environment variables that are currently in place on the system.

lab46:~$ set 

Apple_PubSub_Socket_Render=/tmp/launch-zxcVFC/Render
Apple_Ubiquity_Message=/tmp/launch-h4tdQI/Apple_Ubiquity_Message
BASH=/bin/bash
BASH_ARGC=()
BASH_ARGV=()
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="3" [1]="2" [2]="48" [3]="1" [4]="release" [5]="x86_64-apple-darwin11")
BASH_VERSION='3.2.48(1)-release'
COLUMNS=80
COMMAND_MODE=unix2003
DIRSTACK=()
DISPLAY=/tmp/launch-nlv4HI/org.x:0
EUID=501
GROUPS=()
HISTFILE=/Users/Thomas/.bash_history
HISTFILESIZE=500
HISTSIZE=500
HOME=/Users/Thomas
HOSTNAME=Thomass-MacBook-Pro.local
HOSTTYPE=x86_64
IFS=$' \t\n'
LANG=en_US.UTF-8
LINES=24
LOGNAME=Thomas
MACHTYPE=x86_64-apple-darwin11
MAILCHECK=60
OPTERR=1
OPTIND=1
OSTYPE=darwin11
PATH=/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
PIPESTATUS=([0]="0")
PPID=649
PROMPT_COMMAND='update_terminal_cwd; '
PS1='\h:\W \u\$ '
PS2='> '
PS4='+ '
PWD=/Users/Thomas
SECURITYSESSIONID=186a5
SHELL=/bin/bash
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
SHLVL=1
SSH_AUTH_SOCK=/tmp/launch-3MwPil/Listeners
TERM=xterm-color
TERM_PROGRAM=Apple_Terminal
TERM_PROGRAM_VERSION=303
TERM_SESSION_ID=C4D3E870-C900-43E5-8C99-DD82C82ED39A
TMPDIR=/var/folders/s_/4x3d698174b8cn1l1c0m1mkm0000gn/T/
UID=501
USER=Thomas
_=/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
__CF_USER_TEXT_ENCODING=0x1F5:0:0
update_terminal_cwd () 
{ 
    local SEARCH=' ';
    local REPLACE='%20';
    local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}";
    printf '\e]7;%s\a' "$PWD_URL"
}

You are able to change an environment variable by setting it equal to some value

lab46:~$ echo $TERM
xterm-color
lab46:~$ TERM=xterm
lab46:~$ echo $TERM
xterm
lab46:~$

Wildcards

Wildcards are a magical operator that allows the unix system to search for the beginning characters + 0 or more characters. They are very useful for searching for a very long file or searching for one that you do not know the rest of the name.

Demonstration

In this example I will be searching for a file named 'diablo3looksprettygood.jpg' within my home directory of /home/thakes3.

lab46:~$ find /home/thakes3 --name 'diablo*' 2> /dev/null
diablo3looksprettygood.jpg
lab46:~$

Note that it found the exact file even though we did not specify the rest of it.

I can also use vi on a different file 'lulzjkidkroflhahanoob.txt'

lab46:~$ vi lulz*

unix Objective

unix Objective

State the course objective

Definition

In your own words, define what that objective entails.

Method

State the method you will use for measuring successful academic/intellectual achievement of this objective.

Measurement

Follow your method and obtain a measurement. Document the results here.

Analysis

Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.

  • How did you do?
  • Is there room for improvement?
  • Could the measurement process be enhanced to be more effective?
  • Do you think this enhancement would be efficient to employ?
  • Could the course objective be altered to be more applicable? How would you alter it?
opus/spring2012/thakes3/unixpart3.txt · Last modified: 2012/05/08 14:03 by thakes3