260 likes | 369 Views
Unix review Info 427. Announcements. Schedule posted on OnCourse Click the Wiki link to find it Readings, resources, assignments will be posted here Please use OnCourse Forum to ask questions. Our Plan. We want to understand how search engines work
E N D
Announcements • Schedule posted on OnCourse • Click the Wiki link to find it • Readings, resources, assignments will be posted here • Please use OnCourse Forum to ask questions
Our Plan • We want to understand how search engines work • The best way to do this is to build one! • But first we need to catch up on Unix and Perl, which will make up our toolbox…
Unix Never heard of Expert
Perl Never heard of Expert
PageRank Never heard of Expert
HTTP Never heard of Expert
Emacs Never heard of Expert
Breadth first search Never heard of Expert
Concerns • Learning Perl (9) • Amount of time needed for assignments (7) • Difficulty of programming (5) • Still on waitlist (2) • Working in teams (2) • (And other singletons…)
Unix: logging in and out • Logging into a unix server: • If you have a windows computer, use putty • If you have a Mac or Linux computer, use the Terminal [djcran@pikachu ~]$ sshdjcran@burrow.soic.indiana.edu djcran@burrow.soic.indiana.edu'spassword: Last login: Thu Jan 13 00:15:24 2011 from pikachu.soic.indiana.edu [djcran@burrow ~]$ • Logging out: [djcran@capricorn ~]$ exit
Some basic commands • ls– lists files in current directory • ls –l– lists file details (“l” for “long”) • ls –a – lists all files (“a” for “all”) • Without –a option, filenames beginning with a dot are not shown to you • ls –al – lists all files (“a” stands for “all”)
[djcran@capricorn ~]$ ls i427 public_html [djcran@capricorn ~]$ ls -l total 8 drwxrwxr-x 2 djcrandjcran 4096 Jan 12 12:59 i427 drwxr-xr-x 2 djcrandjcran 4096 Jan 5 12:30 public_html [djcran@capricorn ~]$ ls -la total 68 drwx------ 7 djcrandjcran 4096 Jan 13 00:15 . drwxr-xr-x 102 root root 4096 Jan 5 12:48 .. -rw------- 1 djcrandjcran 1382 Jan 13 00:15 .bash_history -rw-r--r-- 1 djcrandjcran 33 Jan 5 12:30 .bash_logout -rw-r--r-- 1 djcrandjcran 176 Jan 5 12:30 .bash_profile -rw-r--r-- 1 djcrandjcran 124 Jan 5 12:30 .bashrc -rw-r--r-- 1 djcrandjcran 515 Jan 5 12:30 .emacs drwxrwxr-x 3 djcrandjcran 4096 Jan 12 13:03 .emacs.d drwxrwxr-x 2 djcrandjcran 4096 Jan 12 12:59 i427 drwxr-xr-x 3 djcrandjcran 4096 Jan 5 12:30 .kde -rw------- 1 djcrandjcran 46 Jan 13 00:21 .lesshst drwxr-xr-x 4 djcrandjcran 4096 Jan 5 12:30 .mozilla drwxr-xr-x 2 djcrandjcran 4096 Jan 5 12:30 public_html -rw------- 1 djcrandjcran 596 Jan 12 12:59 .viminfo -rw------- 1 djcrandjcran 158 Jan 13 00:15 .Xauthority -rw-r--r-- 1 djcrandjcran 658 Jan 5 12:30 .zshrc [djcran@capricorn ~]$
Directories • Hierarchical tree structure just like the folders in Windows or MacOS • The root directory of the filesystem is named / • Your home directory is /u/<username>/ As a shortcut, you can refer to it as ~ • At any point in time, you’re in exactly 1 directory • Navigate the directory structure using cd(“change directory”) • You can refer to directories starting from the root, like: ls /u/djcran/i427/ or relative to the directory you’re currently in, like this: cd /u/djcran ls i427/
Making directories • mkdir courses • mkdir courses/I400 • mkdir courses/I500 • cd courses/I500 • mkdir lectures • mkdir ~/personal • cd ~ ~ courses www personal I500 I400 images lectures
Moving around: example • Change directory • cd www/images • cd ~/courses • cdI400 • cd../I500 • cd lectures • cd./lectures ~ courses www personal I500 I400 images Special directory names: / The root ~ Your home directory . The current directory .. The parent directory lectures
Removing directories • Use rmdirto delete an empty directory: [djcran@capricorn ~]$ mkdir bad [djcran@capricorn ~]$ mkdir bad/directory [djcran@capricorn ~]$ rmdir bad rmdir: bad: Directory not empty [djcran@capricorn ~]$ cd bad [djcran@capricorn bad]$ rmdir directory [djcran@capricorn bad]$ cd .. [djcran@capricorn ~]$ rm bad rm: cannot remove `bad': Is a directory [djcran@capricorn ~]$ rmdir bad [djcran@capricorn ~]$
Getting help • Unix commands often have many, many options • Unix commands are very powerful (good), but remembering all of the options is impossible (bad) • Use man to display help (“manual”) for a command • E.g. man ls • Most commands also have a --help or –h option [djcran@capricorn ~]$ ls --help Usage: ls [OPTION]... [FILE]... List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor --sort. Mandatory arguments to long options are mandatory for short options too. -a, --all do not ignore entries starting with . -A, --almost-all do not list implied . and .. --author with -l, print the author of each file -b, --escape print octal escapes for nongraphic characters --block-size=SIZE use SIZE-byte blocks -B, --ignore-backups do not list implied entries ending with ~ -c with -lt: sort by, and show, ctime (time of last modification of file status information) with -l: show ctime and sort by name otherwise: sort by ctime -C list entries by columns --color[=WHEN] control whether color is used to distinguish file types. WHEN may be `never', `always', or `auto' -d, --directory list directory entries instead of contents, and do not dereference symbolic links -D, --dired generate output designed for Emacs' dired mode -f do not sort, enable -aU, disable -lst -F, --classify append indicator (one of */=>@|) to entries --file-type likewise, except do not append `*' --format=WORD across -x, commas -m, horizontal -x, long -l, single-column -1, verbose -l, vertical -C --full-time like -l --time-style=full-iso -g like -l, but do not list owner -G, --no-group like -l, but do not list group -h, --human-readable with -l, print sizes in human readable format
Working with files • cp - Make a copy of a file • mv - Rename or move a file • rm - Delete (remove) a file [djcran@capricorn i427]$ ls file.txt [djcran@capricorn i427]$ cp file.txtfile.txt.backup [djcran@capricorn i427]$ ls file.txtfile.txt.backup [djcran@capricorn i427]$ mkdir backups [djcran@capricorn i427]$ mvfile.txt.backup backups/ [djcran@capricorn i427]$ ls backups file.txt [djcran@capricorn i427]$ ls backups/ file.txt.backup
Looking inside files • cat • more • less • tail • head • grep
Working with multiple files • You can use the special character * to refer to multiple files • cp * backup/ • rmt* • rmt * • mv *.txt old/ • WARNING: Be extremely careful when moving or renaming files • Unix trusts that you know what you are doing • E.g. If you type rm *, it will immediately and permanently remove all files in your current directory • E.g. If you type mv file1 file2, but file2 already exists, Unix will immediately and permanently overwrite the contents of file2 • So be careful, and make frequent backups!
Redirection and piping • Sends the output of a command to a file • Redirect stdout (“standard output”) using > e.g.ls -l > file • WARNING: file will be overwritten, if it exists. Use >> to append to the end of an existing file. [djcran@capricorn ~]$ ls -la > file [djcran@capricorn ~]$ head file total 68 drwx------ 7 djcrandjcran 4096 Jan 13 02:03 . drwxr-xr-x 102 root root 4096 Jan 5 12:48 .. -rw------- 1 djcrandjcran 1382 Jan 13 00:15 .bash_history -rw-r--r-- 1 djcrandjcran 33 Jan 5 12:30 .bash_logout -rw-r--r-- 1 djcrandjcran 176 Jan 5 12:30 .bash_profile -rw-r--r-- 1 djcrandjcran 124 Jan 5 12:30 .bashrc -rw-r--r-- 1 djcrandjcran 515 Jan 5 12:30 .emacs drwxrwxr-x 3 djcrandjcran 4096 Jan 12 13:03 .emacs.d -rw-rw-r-- 1 djcrandjcran 0 Jan 13 02:03 file
Piping • Piping is used to send the output of one command to the input of another • Use the output of command1 as the input to command2: command1 | command2 • Very powerful! • E.g. Count the number of files in the current directory ls | wc -l • E.g. display only the first 2 lines of the manual page for “ls” man ls | head –n 2 • Count how many lines of the manual page for “ls” include the word “the” man ls | grep the | wc -l
Job Control top lists the processes running on the system w lists the users logged into the system ps lists your processes kill process-id kills the specified process Control-C kills the current process Control-Z suspends the current process fgun-suspends a process
Text editors • The two popular Unix editors are emacsand vi • Both are extremely powerful. People argue about which is better, but it’s just a personal choice. • Another choice is nano, which is less powerful but easier to learn • We recommend emacs for I427. It’s relatively easy to learn, but is still very powerful. • If you don’t know emacs, check out an online tutorial.
More on UNIX • Tons of books • Tons of online resources • Google “unix tutorial” • Man pages