1 / 52

BASIC UNIX Tutorial One

BASIC UNIX Tutorial One. COMPUTER AND INFORMATION ENGINEERING LAB II ECE 3102 & ECE 4102. رَبِّ زدْنيِ عِلْماً وَ رْزُقْنيِ فَهْما My Lord! Advance me in Knowledge and true understanding . Lecturer: Dr. Nor Farahidah Za’bah Demonstrator: Br. Akhter Lab technician: Br. Shahlan.

sutton
Télécharger la présentation

BASIC UNIX Tutorial One

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. BASIC UNIXTutorial One COMPUTER AND INFORMATION ENGINEERING LAB II ECE 3102 & ECE 4102 رَبِّ زدْنيِ عِلْماً وَ رْزُقْنيِ فَهْما My Lord! Advance me in Knowledge and true understanding.

  2. Lecturer: Dr. Nor FarahidahZa’bahDemonstrator:Br. AkhterLab technician:Br. Shahlan Laboratory: Mechatronics Workshop, Room# E2-2-13.12 رَبِّ زدْنيِ عِلْماً وَ رْزُقْنيِ فَهْما My Lord! Advance me in Knowledge and true understanding.

  3. Introduction • Every computer uses an operating system. • The operating system forms a platform for other system software and application software. • The most popular operating systems in use today are: • Windows from Microsoft • Mac OS from Apple • UNIX / LINUX

  4. General info • Multitasking & Multi-user OS. • Unix has user interfaces called Shells (Terminals)that is more controlled,more flexible and powerful than the standard operating system text-based interface. • Main purpose is to make it easier for the user to manipulate the functions of the operating system

  5. General info (Con.) • Unix is more flexible and can be installed on many different types of machines, • main-frame computers, • Supercomputers • micro-computers. • Unix is more stable, which means, does not go down as often as Windows, so, • Needs less administration and maintenance. • Unix has comparably greater built-in security and permissions features. • Unix possesses much greater processing power.

  6. General info (Con.) • Unix is the leader in serving the Web. • About 90% of the Internet relies on Unix operating systems running Apache, most widely used Web server. • Mostly free or inexpensive open-source operating systems. • Unix also inspires novel approaches to software design, such as, • solving problems by interconnecting simpler tools instead of creating large monolithic application programs.

  7. General info (Con.) Need to Remember One single type of Operating System (OS) can not provide universal answers to all your computing needs.

  8. History • Developed in 1969 by a group of AT&T employees at Bell Labs. • The Unix operating system was first developed in Assembly Language. By 1973 had been almost entirely recoded in C. • Today's Unix systems are split into various branches, developed over time by AT&T as well as various commercial vendors and non-profit organizations. • As of 2007, the owner of the trademark is The Open Group, an industry standards consortium. • Only systems fully compliant with and certified according to the Single UNIX Specification are qualified to use the trademark; others are called, "Unix system-like" or "Unix-like“  Ex: MINIX, Linux, and BSD.

  9. Single UNIX Specification • Outlined by The Open Group, a consortium that holds the UNIX trademark. • Only system that complies with the specification can use the trademark. • Those that not complies are classified as UNIX-like. • Registered UNIX products - • Digital® UNIX, Hewlett Packard HP-UX®, IBM AIX®, SCO UnixWare®, SGI IRIX®, Sun Solaris® • Linux is a product that mimics the form and function of a UNIX system, but is not derived from original UNIX licensed source code and is classified as UNIX-like.

  10. Components • Kernel • Master control of all computer operations. • Controls access to files, • Allocates resources, • Controls input/output (I/O), • Manages memory. • Shell • Command interpreter: • transfers information between user and the Kernel • Common shells: “C” shell, Bourne Shell, Korn Shell. • Shell uses prompt (% or $) to indicate readiness to accept next command. Applications Shell Kernel

  11. Shell or Terminal commands SHELL OR TERMINAL

  12. Files & processes • Everything in UNIX is either a file or a process. • A process is an executing program identified by a unique Process Identifier (PID). • A file is a collection of data. They are created by users using text editors, running compilers etc. • Examples of files: • a document (report, essay etc.) • the text of a program written in some high-level programming language • instructions comprehensible directly to the machine and incomprehensible to a casual user, for example, a collection of binary digits (an executable or binary file); • a directory (or folder in Windows), containing information about its contents, which may be a mixture of other directories (subdirectories) and ordinary files.

  13. UNIX File system • Unix file-store is divided into a tree of directories and sub-directories. • At the very top-level (or bottom level depending on how you look at it) is the root directory,represented by the ‘/’ character. • Users can sub-divide their own directory into a number of sub-directories, so that they may group their files according to the different areas of their work. • Pathname: “directions” to a file through directories and subdirectories

  14. System directories Below are a number of system directories (such as /bin, /lib, /dev) together with the directories for user files.

  15. Home / user directory • Main login directory (the home directory) for the user Fredwho has been allocated to the u1 directory would be /u1/fred. • The full filename or pathname for Fred's file results1 in the subdirectory plants would be /u1/Fred/plants/results1. • If user Fred is working in the default, home directory, then only plants/results1 need be used to refer to the file.

  16. Absolute & relative addressing • Absolute: • Every file has 1 and only 1 absolute address. • Usually starts with a “/” as first character. • Starts at root directory and moves through directories/subdirectories to file. • Can use “~” to start the path at the user level. • Relative: • Describe path to file from current working directory. • Relative addresses are not unique. • Do not need to begin with a “/”.

  17. Relative Addressing (Con.) • Single dot (.) used to signify current working directory. • Double dot (..) used to describe parent (1 step up) directory. • Relative address starts at current level and moves through subdirectories. • Each step (directory/subdirectory) is separated by a “/”.

  18. File Naming conventions • Up to 256 characters in length. • Can start with/be all numbers. • Can use: • period (.) • underscore (_) • dash (-) • comma (,) • Case sensitive (PC usually not). • Do not include spaces in file name.

  19. Wild Characters • Characters that can be used to match a number of different character combinations are called WILD CHARACTERS. • (?) - represents 1 character • ex.: Lab?.c could describe Lab3.c, Lab8.c, LabK.c • (*) - represents more than 1 character • ex.: Lab*.c could describe Lab223.c, LabA1155.c

  20. Examples Relative Address: “.” = current directory “..” = dir. 1 step up “/” = separates steps

  21. Examples (Con.) • Absolute Address of file ex7.c • /home/lookout/a/fred/c/hmwks/ex7.c • Using “~” shortcut to “users” level: ~/c/hmwks/ex7.c

  22. Examples (Con.) If working dir. isfred, relative address of ex7.cis • c/hmwks/ex7.c

  23. Examples (Con.) Relative Address of fredto file “data”: ../../../boreas/b/eric/chm/lab1/data

  24. Concept of directory • Files are grouped in the directory structure. • The file-system is arranged like hierarchical tree (inverted) structure. • The top of the tree is called “root” which usually contains several sub-directories. • In UNIX “/” (forward slash) is used to present the “root”.

  25. Concept of directory (Con.) • Home directory might contain a public_html directory. • public_html directory might contain an “index.html” file. home_directory public_html index.html

  26. Concept of directory (Con.) A file cannot hold a directory or a file! home_directory public_html index.html New_file_or_directory

  27. Concept of directory (Con.) Directories can hold files and other directories / tmp users bin etc backup usern user2 … … user1 file1 public_html index.html

  28. Pathnames • Absolute Pathnames • In the previous tree /users/usern/file1 is an absolute pathname. • Relative pathnames • If you are already in the users directory, the relative pathname for file1 is usern/file1.

  29. Specifying Paths What is the absolute path to index.html? / tmp users bin etc backup usern file1 user2 … … public_html user1 Answer: /users/usern/public_html/index.html index.html

  30. Specifying Paths What is the relative path to index.html (assuming that usern is your working directory) / tmp users bin etc backup usern file1 user2 … … public_html user1 index.html Answer: public_html/index.html

  31. UNIX Commands • ls[names] – list files contained in a directory name or that match a file name. If no name is givenlist those files in current directory. • ls –alist all files including hidden files • ls –llist in long format (including details like permissions, owner, size, etc.), works very much like dir • ls –allist all files (including hidden files) in long format • ls –dl dir_namelists information about the directory, “dir_name”.

  32. UNIX Commands (Con.) • pwd–let you know the absolute pathname of your current working directory (Print Working Directory) • cd [dir] – changedirectory • cd ..–go back to parent directory. • “..” is the relative pathname to the parent directory. • “.” stands for current (working) directory. • “~”– the tilde character can refer to your home directory.

  33. UNIX Commands (Con.) • mkdir directories– create one or more directories. You can specify them by absolute or relative pathnames. • cp • cpfile1 file2 – copy file1 to file2. If there’s already a file2, the old one will be overwritten. • cp file(s) directory – file(s) will be copied to the directory.

  34. UNIX Commands (Con.) • mv sourcefiletargetfile– • basically mv renames sourcefile to targetfile. • If there’s a file with the same name as targetfile, it will be overwritten. • mvworks for directories in a similar fashion.

  35. UNIX Commands (Con.) • rmfile(s) – delete file(s). • rmdirdirectories – delete one or more empty directories. • rm –r directories– can be used to delete non empty directories. • WARNING!!! This will DELETE EVERYTHING in that directory!!! • You can not recover your files after you removed them (unlike Windows OS).

  36. Permissions (file access) • There are three types of file access supported by UNIX. • r – read, view the contents of a file or a directory • w –write, edit file/directory contents • x –execute, run executable file

  37. Permissions (Con.) • User – the person who created the file. • Group – the group owns the file. • Other – the rest of the world. • “754” is a decimal number. But you can represent each digit with a binary number. • 4=>read permission, • 2=> write permission, • 1=> execute permission

  38. Permissions (Con.) read=4; write= 2; execute=1, ‘-’ = 0 rwxr-xr-- 4 + 2 + 1 4 + 0 + 1 4 + 0 + 0 754 USER ACCESS GROUP ACCESS OTHER’S ACCESS

  39. Permissions (Con.) • {rwxr-xr--}is a symbolic way to specify file modes, while {754}is a numeric way. • 7  111, 5 101, 4100 . • How to represent file mode numerically? --x--x–wx • 113 • How to represent bit string symbolically? • 614 • 110 001100 • rw---xr-- Change it to binary numbers

  40. Permissions (Con.) • chmod mode file(s) – another UNIX command! Change the access mode of one or more files. Examples: • chmod 751 my_file– the owner of my_file has rwx(7) permission, the group has r-x(5) permission, others have --x permission. • What the following command will do? • chmodu=rwx,g=r,o=wrmy_file Set Permisson as: Owner to have ‘rwx’ Group to have ‘r’ Other to have ‘rw ‘ Answer: chmod746 my_file

  41. Practice • Create a new directory in your grove account named public_htmlby using the following command, • $ mkdirpublic_html • Go to this directory • $ cdpublic_html • Createa new file named • $ cat >index.html -- create a file This is an html file. -- content of the file ^D <Ctrl. D> -- closing the file

  42. Practice (Con.) • Viewing the content of the file • $ cat index.html This is an html file. • Adding content of the file • $ cat >>index.html Adding second line to the html file. ^D • Viewing the content of the file • $ cat index.html This is an html file. Adding second line to the html file.

  43. Practice (Con.) OR • Use pico to create a new file named index.htm Note: Pico is a simple, display-oriented text editor for UNIX.

  44. Practice (Con.) • After you save the file index.html, change the mode of this file by using the following command, • chmod 644 index.html • (u=rw-, g=r--, o=r--) • Check whether you did it right • ls –l or dir • (What result should be displayed?) • -rwxr-xr--1hansdoc858 Aug 22 22:28 index • Unixfile types, permissions, number of hard links, owner, group, size, date, filename

  45. Practice (Con.) • Then go back to parent directory • cd .. • Change the mode of public_html directory • chmod 755 public_html • ( What’s the meaning of this command?) • Ans: u=rwx, g= r-x, o=r-x • Check if you got the mode set right • ls –dl public_html

  46. Pico Editor • Some short cuts for the pico editor • ^G Get Help • ^O WriteOut • ^R Read File • ^Y PrevPg • ^K Cut Text • ^C Cur Pos • ^X Exit • ^J Justify • ^W Where is • ^V Next Pg • ^U UnCut Text • ^T To Spell

  47. CygWin Emulator • http://www.cygwin.com • Clear screen: $ ^L <Ctrl + L> • For Help: $ help • To exit/close: $ exit • Help on command: $ command_name --help

  48. Basics UNIX command 1 • Listing files and directories • Making Directories • Changing to a different directory  • The directories . and .. • Pathnames • home directories

  49. Basics UNIX command 2 • Copying Files • Moving Files • Removing Files and directories • Displaying the contents of a file on the screen • Searching the contents of a file

  50. Basics UNIX command 3 • Wildcards • Filename Conventions • Getting Help

More Related