Linux Lecture I Notes
Getting a ECE Unix account
1) Go here: ACME
2) Click on the link: "Click here to create or manage your account"
3) Then click reset your password.
SSH Mac Users
1) Open the Terminal application
2) Type: ssh <username>@mario.ece.utexas.edu
3) You will be prompted for your password
Windows Users
1) Go here: PUTTY
2) Click PuTTY.exe
3) In the host name field type this: <username>@mario.ece.utexas.edu
4) Enter password when prompted to
Format of a Command
Command -flags (arguments)
Command: program you are trying to run
Flag: a way for a user to specify what they want a program to do
Arguments: what users pass to the program
Ways to find help.
man <command> - pull up the manual for the given <command>
info <command> - pull up the info page for the given <command>
google
Basic Commands Quick Reference
| pwd | list the path of the directory you are currently in |
| ls | list the files that are in the directory you are in |
| -l: give more details, show permissions | |
| -a: show hidden files | |
| cd (path) | change directory to path. If no path given go to home directory |
| less (file name) | view text files |
| "/" is used to search | |
| "q" is used to quit | |
| history | shows history of commands |
| echo (message) | will echo the message onto the screen |
| cp (file) (destination) | copy the file to the destination |
| -r: copy recursively, use to copy directories | |
| mv (file) (destination) | move file to destination, can also be used to rename a file |
| mkdir (directory name) | make a directory with given name |
| rm | remove a file |
| -r: remove recursively, use to delete directories | |
| touch | creates a file |
| vi | text editor |
| ctrl+c | Cancel an operation |
| ctrl+Z | Suspend an operation |
| bg | send suspended program into the background |
| fg | bring a program into the foreground |
| chmod (rwx)[ugo] | set read write execute privilidges for user groups and others, use octal |
VI Commands Quick Reference
| ESC | enter command mode |
| i | enter insert mode |
| v | enter visual mode |
| y | yank (copy) selected text |
| p | paste |
| u | undo |
| x | delete character |
| dd | delete line |
| yy | yank whole line |
| / | search |
| :(%)s/thing1/thing2/(g) | replace all occurenses of thing1 in file with thing2 |
| j | move down |
| k | move up |
| h | move left |
| l | move right |
| :q | quit |
| :w | save |
| :wq | save then quit |
| :q! | quit without saving |
Symbols Quick Reference
| . | current directory |
| .. | parent directory |
| | | pipe directory |
| ~ | home directory |
| * | wild card |
Shortcut Quick Reference
| TAB | Auto complete |
| UP arrow | browse through history |
Key combination Quick Reference
| ctrl+c | cancel action |
| ctrl+z | suspend action |
Basic regular expression
| . | any character |
| ^ | begining of string |
| $ | end of string |
| ? | matches preceeding character 0 or 1 times: colou?r matches color and colour |
| * | 0 or more of the previous character (? for dont get greedy) |
| + | 1 or more of the previous character (? for dont get greedy) |
| () and 1 | capture [\( in vi and \1 to use] |
| [] | character can be anything within brackets: so [0123456789] matches with 4 |
| - inside of [] | [0123456789] = [0-9] |
| ^ inside of [] | everything not in [], so [^a-z] means anything not lowercase a through z |
| {n} | matches preceding character n number of times: phone number: [0-9]{3}-[0-9]{4} |
| {n,m} | matches preceding character at least n times but not more than m times |
What were going to do today
*consider anything after a # to be a comment, these will be used to make clear what each command does.
*consider anything after a % sign to be a command that was typed into the unix shell
What is a path?
A Path specifies the location of a file or directory in the file system.
There are two kinds: absolute and relative
Your absolute location: /Milky way galaxy/Orion-Cygnus Arm/The Solar System/Earth/North America/United States/Texas/Austin/Central Austin/UT Campus/ACA/1.104
Your relative location: ACA/1.104
Move around
| %pwd | #show me my current path |
| %cd | #move to my home directory |
| %ls | # list the files in this directory |
| Make a directory | |
| %cd | #change into home directory, this way we will all start from the same relative place |
| %mkdir Birds | #make a new directory called Birds |
| %ls | #show files in directory |
| %cd Birds | #change into the Birds directory |
| %mkdir Robin | #makes a directory called Robin in folder ~/Birds |
| %ls | #show files in directory |
| %mkdir BlueJay | #makes a directory called BlueJay |
| %mkdir BlackBirds | #makes a directory called BlackBird |
| %mkdir BrownBird | #make a directory called BrownBirds |
| %ls | # show files in directory |
| Make a text file | |
| %cd ~/Birds/Robin | #changes to the Robin directory |
| %vi birdsrule.txt | #creates a new text file called birdsrule and opens up a text editor called vi |
| #we are now in vi refer to the Vi help page to see more details about commands | |
| %less birdsrule.txt | #allows you to view files, with less you can perform searches |
| Cool background stuff | |
| %cd .. | #changes directory to the next level up in path, in this case we will cd to Birds |
| %pwd | #shows you your present working directory (directory currently in) |
| %cd BlueJay | #move into BlueJay directory |
| %vi bluebirds.txt | #create a text file called bluebirds and open text editor, vi |
| #now in vi | |
| [ctrl+z] | #suspend task |
| %bg | #put the task (vi) that we just suspended into the background |
| %jobs | #shows all tasks that are in background |
| %vi brownbirds | #makes a file called brown birds |
| [ctrl + z] | #suspends taks |
| %bg | # puts taks just suspended in background |
| %jobs | #shows all tasks in background, should show two vi programs |
| %fg | #will bring brownbirds into the fg because that was the last thing to go into the bg |
| [ctrl + z] | #suspends task |
| %bg | #puts task in background |
| %jobs | #shows all tasks in background |
| %fg 1 | #will pull up bluebirds because bluebirds has job #1 |
| #in vi text editor | |
| %cd ../BlackBirds | #will change into blackbird directory |
| %vi blackbirds | # opens a text file called black birds in vi |
| Remove a directory | |
| %cd ~/Birds | # change to Birds directory |
| %rm r BlackBirds | #will remove directory BlackBirds |
| Copy a file | |
| %cd ~/Birds/BlueJay | #change to BlueJay directory |
| %cp brownbirds.txt ~/Birds/BrownBird/ | #will copy brownbirds to the BrownBird folder |
| Copy a folder | |
| %cd ~/Birds/ | #change to Birds directory |
| %cp -r BlueBird ~/Birds/BrownBird/ | #will copy BlueBird to the BrownBird folder |
| Move a file | |
| %cd ~/Birds/BrownBird/ | #change to the brown bird folder |
| %mv brownbirds.txt uglybird.txt | # will move brownbirds.txt to uglybirds.txt |
| Change permissions | |
| %chmod 400 uglybird.txt | # will change permissions of uglybird.txt to read only |
| Set Environment variable | |
| %MYBIRDS=~/Birds | # will set variable $MYBIRDS to the path of the Bird directory |
| See what we did today | |
| %history | #prints all of the commands that we have used on the screen |
| %history | less | #prints history but displays using the less program |
| All Done | |
| %exit | #will log off username *only do this if you are actually logged onto a machine |
Basic regular expression
| . | any character |
| ^ | begining of string |
| $ | end of string |
| ? | matches preceeding character 0 or 1 times: colou?r matches color and colour |
| * | 0 or more of the previous character (? for dont get greedy) |
| + | 1 or more of the previous character (? for dont get greedy) |
| () and 1 | capture [\( in vi and \1 to use] |
| [] | character can be anything within brackets: so [0123456789] matches with 4 |
| - inside of [] | [0123456789] = [0-9] |
| ^ inside of [] | everything not in [], so [^a-z] means anything not lowercase a through z |
| {n} | matches preceding character n number of times: phone number: [0-9]{3}-[0-9]{4} |
| {n,m} | matches preceding character at least n times but not more than m times |
Regular expressions
literal: literal search characters
metacharacter: characters that have special meaning (use \ to espcape and use as literal)
see above table
Practice problems: true or false
"string" =~ /search for/
1) "hello world" =~ /hello/
2) "hello world" =~ /^world/
3) "question" =~ /q[^a-x]/
4) "Iraq" =~ /q[^a-z]/
5) "break" =~ /br[ea]k/
6) "hello" =~ /.{6}/
7) "goodbye" =~ /.*/
8) "" =~ /.+/
9) "mud" =~ /mo?p/
What's next?
1) Practice! Practice! Practice!: try doing some of your homework in a unix environment: 1.7
2) Come to Linux Lecture Part 2: February 22 same time same place: Git, compression, shell scripting
3) Take our survey and let us know how we can improve!