8/29/13 Announcements • Schedule posted on OnCourse – Click the Wiki link to find it – Readings, resources, assignments will be posted here Unix review • Please use OnCourse Forum to ask quesMons Info 427 Our Plan Unix • 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… 12 10 8 6 4 2 0 Never heard of Perl PageRank 20 20 15 15 10 10 5 5 0 Never heard of Expert Expert 0 Never heard of Expert 1 8/29/13 HTTP Emacs 14 8 12 6 10 8 4 6 4 2 2 0 Never heard of 0 Expert Breadth first search 6 4 2 0 Never heard of • Logging into a unix server: – If you have a windows computer, use pu]y – If you have a Mac or Linux computer, use the Terminal [djcran@pikachu ~]$ ssh djcran@burrow.soic.indiana.edu! djcran@burrow.soic.indiana.edu's password: ! Last login: Thu Jan 13 00:15:24 2011 from pikachu.soic.indiana.edu! [djcran@burrow ~]$! ! Learning Perl (9) Amount of Mme needed for assignments (7) Difficulty of programming (5) SMll on waitlist (2) Working in teams (2) (And other singletons…) Expert Unix: logging in and out • Logging out: Expert Concerns • • • • • • 8 Never heard of 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 opMon, filenames beginning with a dot are not shown to you • ls –al – lists all files (“a” stands for “all”) ! [djcran@capricorn ~]$ exit! ! ! ! 2 8/29/13 [djcran@capricorn ~]$ ls! i427 public_html! ! [djcran@capricorn ~]$ ls -l! total 8! drwxrwxr-x 2 djcran djcran 4096 Jan 12 12:59 i427! drwxr-xr-x 2 djcran djcran 4096 Jan 5 12:30 public_html! [djcran@capricorn ~]$ ls -la! total 68! drwx-----7 djcran djcran 4096 Jan 13 00:15 .! drwxr-xr-x 102 root root 4096 Jan 5 12:48 ..! -rw------1 djcran djcran 1382 Jan 13 00:15 .bash_history! -rw-r--r-1 djcran djcran 33 Jan 5 12:30 .bash_logout! -rw-r--r-1 djcran djcran 176 Jan 5 12:30 .bash_profile! -rw-r--r-1 djcran djcran 124 Jan 5 12:30 .bashrc! -rw-r--r-1 djcran djcran 515 Jan 5 12:30 .emacs! drwxrwxr-x 3 djcran djcran 4096 Jan 12 13:03 .emacs.d! drwxrwxr-x 2 djcran djcran 4096 Jan 12 12:59 i427! drwxr-xr-x 3 djcran djcran 4096 Jan 5 12:30 .kde! -rw------1 djcran djcran 46 Jan 13 00:21 .lesshst! drwxr-xr-x 4 djcran djcran 4096 Jan 5 12:30 .mozilla! drwxr-xr-x 2 djcran djcran 4096 Jan 5 12:30 public_html! -rw------1 djcran djcran 596 Jan 12 12:59 .viminfo! -rw------1 djcran djcran 158 Jan 13 00:15 .Xauthority! -rw-r--r-1 djcran djcran 658 Jan 5 12:30 .zshrc! [djcran@capricorn ~]$ ! ! Making directories • • • • • • • mkdir courses mkdir courses/I400 mkdir courses/I500 cd courses/I500 mkdir lectures mkdir ~/personal cd ~ I500! • 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 Mme, you’re in exactly 1 directory – Navigate the directory structure using cd (“change directory”) – You can refer to directories starMng from the root, like: ls /u/djcran/i427/! or relaMve to the directory you’re currently in, like this: !! !cd /u/djcran !! !! !ls i427/ Moving around: example • Change directory ~! personal! courses! Directories I400! lectures! Removing directories • Use rmdir to 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 ~]$ ! !! www! images! – cd www/images – cd ~/courses – cd I400 – cd ../I500 – cd lectures – cd ./lectures Special directory names: / The root ~ Your home directory . The current directory .. The parent directory ~! personal! courses! I500! I400! www! images! lectures! Gekng help • Unix commands olen have many, many opMons – Unix commands are very powerful (good), but remembering all of the opMons is impossible (bad) • Use man to display help (“manual”) for a command – E.g. man ls! • Most commands also have a -­‐-­‐help or –h opMon [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! 3 8/29/13 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.txt file.txt.backup! [djcran@capricorn i427]$ ls! file.txt file.txt.backup! [djcran@capricorn i427]$ mkdir backups! [djcran@capricorn i427]$ mv file.txt.backup backups/! [djcran@capricorn i427]$ ls! backups file.txt! [djcran@capricorn i427]$ ls backups/! file.txt.backup! Working with mulMple files • You can use the special character * to refer to mulMple files – – – – cp rm rm mv * backup/!! t*! t *! *.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! Looking inside files • • • • • • cat more less tail head grep Customizing your shell • Special hidden file in home directory – .(t)cshrc, .bashrc, or .login depending on shell – Use ps to find your shell, chsh to change it • Making aliases permanent – Write them in your .cshrc file – alias ll ls –lF – Make them effecMve now: source .tcshrc • Other useful stuff – auto-­‐tabbing: set autolist – prompt: set prompt='%B%m:%~%#%b ’ – colors: setenv CLICOLOR 1 setenv LSCOLORS dxfxcxdxbxegedabagacad Parameters to shell scripts • perl scripuile arg0 arg1 arg2 … • Example: mkdir $ARGV[0]; `cp * $ARGV[0] `; – Creates a directory and copies all files in current working directory to it Alias • Used to rename commands • Alias abbreviaMon command • Example – alias dir ‘ls –lF’ • Stays current unMl you logout 4 8/29/13 Permissions and chmod Example and absolute permissions • chmod who[operaMon][permission] files • Who: u (user) g (group) o (others) a (all) • Permission: r (read) w (write) x (execute) drwxrwxrwx u g o • Operation: + (add) – (remove) • Examples – chmod o+rx * – chmod go-r * % ls -lF total 3 drwx------ 31 drwxrwxrwx 20 -rwxrwxr-x 5 % chmod go-rwx % ls -lF total 3 drwx------ 31 drwxrwxrwx 20 -rwx-----5 % _ fil staff fil staff fil staff file.txt 1054 Aug 19 16:46 Documents/ 680 Aug 19 16:46 Research/ 170 Jul 29 15:34 file.txt fil fil fil 1054 Aug 19 16:46 Documents/ 680 Aug 19 16:46 Research/ 170 Jul 29 15:34 file.txt staff staff staff drwxr-xr-- 111=7 101=5 100=4 Absolute permissions • • • • • • • • • 0400 0200 0100 0040 0020 0010 0004 0002 0001 Owner can read file Owner can write to the file Owner can execute the file Group can read file Group can write to the file Group can execute the file Others can read file Others can write to the file Others can execute the file Absolute permissions • OR (add) the values to make composite permissions • 0400 or 0100 = 0500 • chmod 666 * • chmod 751 * • chmod 777 * • Careful! RedirecMon 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 overwri]en, if it exists. Use >> to append to the end of an exisMng file. [djcran@capricorn ~]$ [djcran@capricorn ~]$ total 68! drwx-----7 djcran drwxr-xr-x 102 root -rw------1 djcran -rw-r--r-1 djcran -rw-r--r-1 djcran -rw-r--r-1 djcran -rw-r--r-1 djcran drwxrwxr-x 3 djcran -rw-rw-r-1 djcran ls -la > file! head file! djcran root djcran djcran djcran djcran djcran djcran djcran 4096 4096 1382 33 176 124 515 4096 0 Jan Jan Jan Jan Jan Jan Jan Jan Jan 13 5 13 5 5 5 5 12 13 02:03 12:48 00:15 12:30 12:30 12:30 12:30 13:03 02:03 .! ..! .bash_history! .bash_logout! .bash_profile! .bashrc! .emacs! .emacs.d! 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! ! 5 8/29/13 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 !fg! ! ! ! !un-­‐suspends a process Job Control • command & puts command in background • Ctrl-­‐z suspends job • %job# restart job # jobs) • bg %job# puts job in background • fg %job# puts job in foreground • nice command runs process “nicely” (from Packaging (archiving) files • tar –cvf file_name.tar directory_name • Move one directory above www tar –cvf www.tar www • Test it: mkdir newww; cp www.tar newww cd newww tar –xvf www.tar • Use z opMon and .tgz extension to create/extract compressed archives Text editors • The two popular Unix editors are emacs and vi – Both are extremely powerful. People argue about which is be]er, 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 relaMvely easy to learn, but is sMll 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 6