UNIX Basics Internet Technology
What is UNIX? Operating System Characteristics Types (flavors) of Unix An operating system (OS) is software that enable the computer to function Developed in 1960’s at Bell Laboratories OS for servers Fundamental building block of the Internet Characteristics Multi-user, multi-tasking Powerful & efficient Reliable & robust First “open” system Freeware → created to develop as a public collaboration A command line interface Types (flavors) of Unix BSD (Berkley): most well-known System V (AT&T) : first commercial Unix Linux: Unix on PC Mac OS X: Unix by Apple Internet Technology
Unix Basics Unix: The Good, Bad & Ugly Unix Fundamentals 9/14/2018 Unix Basics Unix: The Good, Bad & Ugly It does what you say no prompting, "Are you sure?" It's not intuitive Designed by & for engineers It's CASE SENSITIVE Unix Fundamentals Know the difference between a directory and a file Know what directory you are in When in directory doubt, type ‘pwd‘ Internet Technology
Unix Basics: File System 9/14/2018 Unix Basics: File System Hierarchical Naming No explicit disk drives e.g., /home/kiyang (vs. C:\Document and Settings\kiyang) Top level is called the root (e.g. cd /) Absolute (full) vs. relative path (filename) Full path: /home/kiyang/file1.txt Relative path: file1.txt (current directory = /home/kiyang) Navigation No graphical interface or desktop utility Command line using Unix commands pwd (where am I?) ls -l (what are the files in the current directory?) cd dirname (move to a directory named dirname) Internet Technology
Unix: Directories File and directory paths use the forward slash “/” 9/14/2018 Unix: Directories File and directory paths use the forward slash “/” / "root" directory /home/kiyang subdirectory “home” → subdirectory “kiyang” root ~ Unix Home directory shorthand ~kiyang = /home/kiyang ~batman = /home/stud/batman ~/ = (current) user’s home directory ~/public_html/ = user’s web directory ~/IT/homework/ = user’s homework directory home usr kiyang stud batman catwoman IT public_html IT /home/stud/catwoman/public_html (http://widit.knu.ac.kr/~catwoman/) public_html homework homework ithw /home/stud/batman/IT/homework symbolic link created by ‘ln –s’ command Internet Technology
Unix: Command Syntax Unix command syntax: 9/14/2018 Unix: Command Syntax Unix command syntax: command [space] option switches [space] arguments To get help on a command Type ‘man command’ e.g., man ls (example) ls -l /home/kiyang/share Internet Technology
Unix Basics: ls Command 9/14/2018 Unix Basics: ls Command ls lists files in a directory Default argument = current directory Common options: -a → list all files including dot files -s → list files sizes -l → display detailed info Options can be combined, for example: ls –la List detailed info of all files (including dot files) in current directory ls -al List detailed info of hw1.txt in kiyang’s share directory ls -l /home/kiyang/share/hw1.txt List detailed info of files that starts with hw in current directory ls -l hw* Internet Technology
Unix Basics: cd Command 9/14/2018 Unix Basics: cd Command cd dir_name Change directory to the directory named dir_name To change to userid’s homework directory cd /home/stud/userid/IT/homework cd ~userid/IT/homework To change to your own homework directory cd ~/IT/homework cd IT/homework (from home directory) cd homework (from IT directory) Default argument = home directory e.g., cd (change to home directory) .. parent directory e.g., cd .. (change to parent directory) Internet Technology
Unix Basics: Other Command 9/14/2018 Unix Basics: Other Command cp file1 file2 copy file1 to file2 mv file1 file2 rename file1 to file2 rm file1 delete file1 mkdir dir_name to create a directory named dir_name rmdir dir_name to delete a directory named dir_name cat filename display the content of filename more filename display filename content a screen at a time less filename same as more & scroll back Internet Technology
UNIX Shortcuts Up arrow Tab key after partial filename 9/14/2018 UNIX Shortcuts Up arrow Cycles through previous commands Tab key after partial filename Completes the filename if enough has been typed (like auto-complete) Aliases (~/.aliases) Use shorter commands in place of longer one. Syntax: alias short_cmd=‘long command’ e.g., alias dir='ls -al |more' alias cdit='cd ~/IT/homework' alias cdw='cd ~/public_html' alias chmo='chmod 755 ~/IT/homework/*' Internet Technology
Unix Basics: Working with Files 9/14/2018 Unix Basics: Working with Files Files have owners and permissions Owner = person who created the file Permission read, write, execute by owner, group, everyone Cannot "more" all files read permission needed Special files Dot files: ls –a to list Symbolic links: ls –I to list the original file "ls" to list "cp" to copy "mv" to rename. "rm" to delete "more" (less, cat) to view the content Try: ls -l /etc/motd Try "cp" to copy: cp /etc/motd ~/motd.my.copy Try "mv" to rename: mv motd.my.copy blah Try "rm" to delete (forever): rm blah Directories are special types of files mkdir blahdir ("rmdir" to remove) cp /etc/motd ~/blahdir ("ls blahdir" to view) Internet Technology
Unix Basics: Working with Directories 9/14/2018 Unix Basics: Working with Directories Directories are special types of files Unix filesystem is hierarchical use "cd" and "ls" to get around cannot "cd" everywhere due to file access restrictions execute permission needed ~/ your home directory ~/public_html = /home/kiyang/public_html "cd" to change directory "mkdir" to create "rmdir" to remove "pwd" to print current working cirectory "cd" alone brings you home (RUBY slippers!) "cd ~" and "cd ~username" brings you home (or to "username's" home) "cd.." brings you down a directory Internet Technology
Unix Basics: Permissions 9/14/2018 Unix Basics: Permissions The system administrator sets the default permissions Permissions allow you to share or protect information Set up into three user groups owner, group, and world. chmod to change permissions e.g., chmod 755 hw1.txt Internet Technology
Unix Permissions - rwx r-x r-- 111 101 100 7 5 4 9/14/2018 Unix Permissions Unix file permissions are represented in octal (based on binary) -rwxr-xr-- 1 kiyang kiyang 30 May 25 16:17 hw1.txt 000 = 0 = - - - 001 = 1 = - - x 010 = 2 = - w - 011 = 3 = - w x 100 = 4 = r - - 101 = 5 = r - x 110 = 6 = r w - 111 = 7 = r w x owner group world - rwx r-x r-- 1=Allowed 0=Not Allowed 111 101 100 In decimal number 7 5 4 So, the permissions for the file hw1.txt are 754. Internet Technology
9/14/2018 Unix Permissions WIDIT: ~/public_html -> ls -l total 118 -rwxr--r-- 1 robin superG 30 2013-03-19 16:17 hw1.txt -rw-r-xr-x 1 robin robin 221 2013-03-19 16:19 index.htm -rw-r--r-- 1 robin robin 28672 2013-03-22 16:21 lab1.doc lrwxrwxrwx 1 robin robin 15 2013-03-22 16:20 ithw -> ../IT/homework/ drwx--x--x 2 robin robin 4096 2013-03-31 16:21 test file type permission owner group size last modified date name Shows files and directories, owners, file sizes, last modified date, and permissions File hw1.txt has read, write, and execute permissions for owner (robin) and read permissions for group (superG) and the world test is a directory ithw is a symbolic link to ~/IT/homework Internet Technology
Changing Unix File Permissions 9/14/2018 Changing Unix File Permissions Use the chmod command Syntax: chmod permissions filename e.g., chmod 754 hw1.txt This would change the permissions to? Important in web authoring Web pages Must be world readable → chmod 644 (rw- r-- r--) index.htm Server-side Programs Must be executable → chmod 755 (rwx r-x r-x) roster.cgi User group depending on web server configuration Directories Must be world executable → chmod 711 (rwx --x --x) public_html Internet Technology
Unix Permissions: In English 9/14/2018 Unix Permissions: In English Whose permission? u (owner), g (group), o (world), a (all) What action? + (give), - (take away) What rights? r (read), w (write), x (execute) Syntax chmod who+action+rights Examples chmod u+rwx file1.txt (give owner read, write, execute rights) chmod go+rx file1.txt (give group & world read and execute rights) → after both of these commands have executed, the file rights will be 755. Internet Technology
UNIX Network Tools nslookup Ping UNIX command for a DNS name look up 9/14/2018 UNIX Network Tools nslookup UNIX command for a DNS name look up Translates hostname to IP address Syntax: nslookup hostname e.g., nslookup widit.knu.ac.kr Ping Utility for determe if an Internet host is alive & responding e.g. ping –c 5 www.knu.ac.kr Internet Technology