A Unix-like system is one that behaves in amanner similar to a Unix system.Examples of Unix-like systems are:��Introductio...
IntroductionThe Open Group, an industrystandards consortium, owns theUNIX trademark.Dennis Ritchie, one of the originalcre...
Unix filesystem and shell (I)2.1 Unix system structureA computer systemconsists of hardware andsystems software (OS)that to...
Different UNIX variants have different implementations of differentsubsystems.Unix filesystem and shell (I)2.2 Kernel subsyste...
���A process is a running instance of a program.At any given point in time, the CPU is operatingwithin the execution conte...
��Memory managerUnix filesystem and shell (I)2.2 Kernel subsystems (cont’d)Responsible for controlling process access to th...
���Manages access to data and metadata of the files,and organizes the available space of the device(s)which contain it.A Un...
Network stack (TCP/IP)Unix filesystem and shell (I)2.2 Kernel subsystems (cont’d)Unix-like operating systems are known for ...
Unix filesystem and shell (I)2.3 The shellA command line interface to the operating system.Used to execute other programs, ...
Unix filesystem and shell (I)2.4 Simple command examplespwdlsaddusertopmkdirpswhodfcdPrint name of current/working director...
Unix filesystem and shell (I)2.5 Shell scriptingA shell script is a regular text file that conatains shell orUnix commands.U...
Unix filesystem and shell (I)2.6 Options and parameters$ ls -l /binParameters are pieces of information (e.g., a filename) t...
man:whatis:Display entries from Unix onlinedocumentation.example: man mkdirDisplays a single line information about acomma...
Unix filesystem and shell (I)2.7 Getting help (cont’d)$ man mkdirMKDIR(1) USER COMMANDS MKDIR(1)NAMEmkdir - make a director...
Each user owns some quota of the total disk spacefor storage of personal files, mail etc. This portionof the filesystem is v...
Unix filesystem and shell (II)3.1 Security fundamentals (cont’d)���A set of users can form a group.Each user is a member of...
Unix filesystem and shell (II)3.1 Security fundamentals (cont’d)��Any Unix-like operating system has a special usercalled r...
Can a given file be read or written to by aparticular user?What users can run a specific program? Can a userterminate a runn...
Unix filesystem and shell (II)3.2 Unix file hierarchyFiles and directories areorganized in ahierarchical treestructure.In Un...
Unix filesystem and shell (II)3.3 Working directoryEvery running process has a current workingdirectory.A nickname for the ...
Unix filesystem and shell (II)3.4 File path (relative vs. absolute paths)To identify a specific file, the operating system us...
Unix filesystem and shell (II)3.5 The file abstractionUnix follows the mantra: “everything is a file.” As mentionedearlier, a...
Unix filesystem and shell (II)3.6 DirectoriesA directory is a list of files with associatedinformation.Every user has a home...
Unix filesystem and shell (II)3.7 Tilde expansionMost shells support the ~ operator (called tilde).~ expands to my home dir...
Unix filesystem and shell (II)cat3.8 The cat, more and less commandsCopies the contents of a file to the terminal. Wheninvok...
Unix filesystem and shell (II)3.9 Common utilitiespwdlsaddusertopmkdirrmdirpswhodfcdvinanormmvcptouchwcfilemountumountdatee...
Unix filesystem and shell (III)4.1 File permissionsUnix file permissions010204010204010204suidsgidstickyreadwriteexecuteuser...
Example:Unix filesystem and shell (III)4.1 File permissions (cont’d)readwriteexecuteuser group others01040401010204557A com...
Unix filesystem and shell (III)4.2 Directory permissionsSimilar to ordinary file permissions.Read means that the process may...
Unix filesystem and shell (III)4.3 Reading ls output-rwxr--r-- 1 root root 4096 Sep 10 21:11 fooPermissions for User (Owner...
Unix filesystem and shell (III)4.4 Manipulating file attributeschown� Used to change file owner.chgrp� Used to change file gro...
Unix filesystem and shell (III)4.4 Manipulating file attributes (cont’d)Symbolic access modes� chmod u, g, o +/- r, w, x$ ls...
Unix filesystem and shell (III)4.5 File system internalsProcess table��The process table is a data structure in thecomputer...
Unix filesystem and shell (III)4.5 File system internals (cont’d)Open file table��The open-file table contains an entry for e...
Unix filesystem and shell (III)4.5 File system internals (cont’d)pid #10 fd #0fd #1fd #2fd #3fd #4statusoffsetetc.pid #11pid...
Unix filesystem and shell (III)4.6 Commands for file/process informationShows a report of all open files and theprocesses tha...
Unix filesystem and shell (IV)5.1 The standard in/out/errEntry 0: Standard input is data (often text) goinginto a program.E...
Unix filesystem and shell (IV)5.2 DevicesIn Unix, devices are treated just like ordinary files.Entries in the /dev file syste...
Unix filesystem and shell (IV)5.3 RedirectionBefore a command is executed, the input and output can be changed(redirected) ...
Unix filesystem and shell (IV)5.4 Mounting file systemsWhen the system starts, the directory treecorresponds to the file syst...
Unix filesystem and shell (IV)5.4 Mounting file systems (cont’d)/ab//aabbab//a/bDevice Mount pointroot device external device
Unix filesystem and shell (IV)5.5 LinksA directory is a list of files and directories.Each directory entry links to a file on...
5.5 Links (cont’d)The ln command is used to create a regular link,often called hard link.Symbolic links (soft links) are c...
Unix filesystem and shell (IV)5.5 Links (cont’d)Hard vs. symbolic linksdirectoryentryfile contentsdirectoryentrydirectoryent...
The Unix find command is used to locate files.This will search the whole system for any files named foo anddisplay their path...
Prints an entry for a directory called ./src/misc (if one exists).find . -path ./sr*sc-path pattern�Find every file under t...
Search for files which permissions matches the provided expression.find . -perm 664-perm p�Same as previous except that thi...
find . -mtime 0 # find files modified between now and 1 day ago# (i.e., within the past 24 hours)find . -mtime -1 # find f...
Upcoming SlideShare
Loading in …5
×

Introduction to Unix-like systems (Part I-IV)

725 views
686 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
725
On SlideShare
0
From Embeds
0
Number of Embeds
417
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Introduction to Unix-like systems (Part I-IV)

  1. 1. A Unix-like system is one that behaves in amanner similar to a Unix system.Examples of Unix-like systems are:��Introduction1.1 What is a Unix-like system?HP-UX,Solaris (mixed open source/proprietary),Mac OS X,BSD (FreeBSD, OpenBSD etc.), andGNU/Linux (Ubuntu, Debian, Fedora etc.)�����PROPRIETARYFREE
  2. 2. IntroductionThe Open Group, an industrystandards consortium, owns theUNIX trademark.Dennis Ritchie, one of the originalcreators of Unix, expressed hisopinion that Unix-like systemssuch as Linux are de facto Unixsystems.��1.1 What is a Unix-like system? (cont’d)
  3. 3. Unix filesystem and shell (I)2.1 Unix system structureA computer systemconsists of hardware andsystems software (OS)that together provide aworking environment forrunning general purposeapplication programs.HardwareKernelShell & utilitiesUser space
  4. 4. Different UNIX variants have different implementations of differentsubsystems.Unix filesystem and shell (I)2.2 Kernel subsystemsProcess managementMemory managementFilesystemNetwork stack (TCP/IP)
  5. 5. ���A process is a running instance of a program.At any given point in time, the CPU is operatingwithin the execution context of a specific process.The process manager is responsible for processscheduling, context-switching, inter-processcommunication etc.Process managementUnix filesystem and shell (I)2.2 Kernel subsystems (cont’d)
  6. 6. ��Memory managerUnix filesystem and shell (I)2.2 Kernel subsystems (cont’d)Responsible for controlling process access to thehardware memory resources.Memory virtualization separates logical memoryfrom physical memory.Provides each process with a uniform address space.Protects the address space of each process from corruptionby other processes.��
  7. 7. ���Manages access to data and metadata of the files,and organizes the available space of the device(s)which contain it.A Unix file is an information container structuredas a sequence of bytes.Most Unix-like systems support several filesystems.FilesystemUnix filesystem and shell (I)2.2 Kernel subsystems (cont’d)
  8. 8. Network stack (TCP/IP)Unix filesystem and shell (I)2.2 Kernel subsystems (cont’d)Unix-like operating systems are known for richEthernet networking support.Unix implements the TCP/IP protocol stack.The Berkeley sockets API provides a high levelinterface to the TCP/IP stack.���
  9. 9. Unix filesystem and shell (I)2.3 The shellA command line interface to the operating system.Used to execute other programs, manage files andprocesses.Users typically interact with a Unix shell using aterminal emulator, e.g., xterm or OS X Terminal.Graphical user interfaces for Unix are sometimesreferred to as graphical shells.����
  10. 10. Unix filesystem and shell (I)2.4 Simple command examplespwdlsaddusertopmkdirpswhodfcdPrint name of current/working directoryList directory contentsAdd a user to the systemDisplay processesMake directoriesReport a snapshot of the current processesShow who is logged onReport file system disk space usageChange directory
  11. 11. Unix filesystem and shell (I)2.5 Shell scriptingA shell script is a regular text file that conatains shell orUnix commands.Useful for automating tasks and storing commandsequences for later execution. Makes life easier for theuser.Some shell scripts run at system startup or shutdown.The /etc/init.d directory contains shell scripts usedto start, stop, or restart system daemons.����
  12. 12. Unix filesystem and shell (I)2.6 Options and parameters$ ls -l /binParameters are pieces of information (e.g., a filename) that the command needs in order to do its job.Flags (or options) are typically composed using ahyphen (-) followed by one or more letters. A flaginstructs the shell to perform the command in aparticular way.
  13. 13. man:whatis:Display entries from Unix onlinedocumentation.example: man mkdirDisplays a single line information about acommand.Unix filesystem and shell (I)2.7 Getting help$ whatis ifconfigifconfig (8) - configure a network interface
  14. 14. Unix filesystem and shell (I)2.7 Getting help (cont’d)$ man mkdirMKDIR(1) USER COMMANDS MKDIR(1)NAMEmkdir - make a directorySYNOPSISmkdir [ -p ] dirname...DESCRIPTIONmkdir creates directories. Standard entries,`.,for thedirectory itself, and `.. for its parent, are made automat-ically.The -p flag allows missing parent directoriesto be created as needed.With the exception of the set-gid bit, thecurrent umask(2V) setting determines the mode in whichdirectories are created. The new directory inherits the set-gidbit of the parent directory. Modes may be modified aftercreation by using chmod(1V).mkdir requires write permission in the parent directory.SEE ALSOchmod(1V), rm(1), mkdir(2v), umask(2V)
  15. 15. Each user owns some quota of the total disk spacefor storage of personal files, mail etc. This portionof the filesystem is visible only to its owner.Users are identified by a unique number, calleduser id.��Unix filesystem and shell (II)3.1 Security fundamentalsA multi-user system is one that allows concurrentaccess by multiple users of a computer.
  16. 16. Unix filesystem and shell (II)3.1 Security fundamentals (cont’d)���A set of users can form a group.Each user is a member of one or more groups.Groups enable users to share material with otherusers. Like users, every group has a uniqueidentifier, called group id.Groups
  17. 17. Unix filesystem and shell (II)3.1 Security fundamentals (cont’d)��Any Unix-like operating system has a special usercalled root (or sometimes superuser).The root user can access every file on the systemand interfere with the activity of running userprograms.The root user
  18. 18. Can a given file be read or written to by aparticular user?What users can run a specific program? Can a userterminate a running process?��Unix filesystem and shell (II)3.1 Security fundamentals (cont’d)Users and groups are used to determine if file orprocess operations can be performed.
  19. 19. Unix filesystem and shell (II)3.2 Unix file hierarchyFiles and directories areorganized in ahierarchical treestructure.In Unix, all files anddirectories appear underthe root directory "/"./(root)/bin /home /usr/home/bin /lib/ls /local/lc
  20. 20. Unix filesystem and shell (II)3.3 Working directoryEvery running process has a current workingdirectory.A nickname for the current working directory of aprocess is “.” (a single period).The pwd (present working directory) commanddisplays your current working directory.���
  21. 21. Unix filesystem and shell (II)3.4 File path (relative vs. absolute paths)To identify a specific file, the operating system uses apathname, which consists of slashes alternating with asequence of directory names that lead to the file.If the first item in the pathname is a slash, the pathnameis said to be absolute. Its starting point is the rootdirectory.If the first item is a directory name or filename, the pathis said to be relative. Its starting point is the currentdirectory.���
  22. 22. Unix filesystem and shell (II)3.5 The file abstractionUnix follows the mantra: “everything is a file.” As mentionedearlier, a Unix file is simply a sequence of bytes.Unix files may have one of the following types:Regular fileDirectorySymbolic linkBlock-oriented device fileCharacter-oriented device filePipe and named pipe (also called FIFO)Socket�������
  23. 23. Unix filesystem and shell (II)3.6 DirectoriesA directory is a list of files with associatedinformation.Every user has a home directory.(/home/<username>)��Creation dateAttributesetc.���
  24. 24. Unix filesystem and shell (II)3.7 Tilde expansionMost shells support the ~ operator (called tilde).~ expands to my home directory~user expands to user’s home directoryUseful since home directory locations varybetween different machines.����~/file /home/<username>/file~alice/file2 /home/alice/file2
  25. 25. Unix filesystem and shell (II)cat3.8 The cat, more and less commandsCopies the contents of a file to the terminal. Wheninvoked with a list of file names, it concatenatesthem. Use the -n flag to show line numbers.more/lessmore shows file contents, one page at a time. lessallows both forward and backward navigation.Programs of this sort are called pagers.
  26. 26. Unix filesystem and shell (II)3.9 Common utilitiespwdlsaddusertopmkdirrmdirpswhodfcdvinanormmvcptouchwcfilemountumountdateechotarpasswdkillnice&
  27. 27. Unix filesystem and shell (III)4.1 File permissionsUnix file permissions010204010204010204suidsgidstickyreadwriteexecuteuser group others
  28. 28. Example:Unix filesystem and shell (III)4.1 File permissions (cont’d)readwriteexecuteuser group others01040401010204557A common method forrepresenting Unixpermissions is usingoctal (base-8) notation.With three-digit octalnotation, each numeralrepresents a differentcomponent of the permissionset: user, group, and othersrespectively.
  29. 29. Unix filesystem and shell (III)4.2 Directory permissionsSimilar to ordinary file permissions.Read means that the process may read directorycontents.Write means that the process can add/remove files.Execute permission on a directory means you cancd to that directory and access its files.����
  30. 30. Unix filesystem and shell (III)4.3 Reading ls output-rwxr--r-- 1 root root 4096 Sep 10 21:11 fooPermissions for User (Owner) of fileDirectory flag; d if a directory, - if a normal file etc.Permissions for GroupPermissions for Otherowner group filenamelink count file sizeThe ls command shows the permissions and groupassociated with files when used with the -l option:
  31. 31. Unix filesystem and shell (III)4.4 Manipulating file attributeschown� Used to change file owner.chgrp� Used to change file group.chmod� Used to change file permissions.
  32. 32. Unix filesystem and shell (III)4.4 Manipulating file attributes (cont’d)Symbolic access modes� chmod u, g, o +/- r, w, x$ ls -la-rw-r--r-- 1 root root 0 foo$ chmod +x foo-rwxr-xr-x 1 root root 0 foo$ chmod g-x foo-rwxr--r-x 1 root root 0 foo
  33. 33. Unix filesystem and shell (III)4.5 File system internalsProcess table��The process table is a data structure in thecomputer’s main memory that holds informationabout the processes currently handled by theoperating system.Each entry in the process table contains a table ofopen file descriptors for that process.
  34. 34. Unix filesystem and shell (III)4.5 File system internals (cont’d)Open file table��The open-file table contains an entry for each openfile for every process.File descriptors are unique to a process – a file thathas been opened by several processes may beassigned different descriptors for each process.
  35. 35. Unix filesystem and shell (III)4.5 File system internals (cont’d)pid #10 fd #0fd #1fd #2fd #3fd #4statusoffsetetc.pid #11pid #12statusoffsetetc.statusoffsetetc.Processtablefd #0fd #1fd #2fd #3fd #4fd #5fd #6fd #0fd #1fd #2fd #3fd #4 memory disk or other deviceOpen-file tableActual file entriesin v-node tableFileFile
  36. 36. Unix filesystem and shell (III)4.6 Commands for file/process informationShows a report of all open files and theprocesses that opened them.Selects the listing of files for theprocesses whose ID numbers are in thecomma-separated set s.List information about every processnow running.lsoflsof -p sps -e
  37. 37. Unix filesystem and shell (IV)5.1 The standard in/out/errEntry 0: Standard input is data (often text) goinginto a program.Entry 1: Standard output is the stream where aprogram writes its output.Entry 2: Standard error is typically used byprograms to output error messages or diagnostics.The first three entries in the file descriptor tableare preset:���
  38. 38. Unix filesystem and shell (IV)5.2 DevicesIn Unix, devices are treated just like ordinary files.Entries in the /dev file system are device driverinterfaces. Applications interact with the deviceusing standard I/O system calls./dev/tty represents the terminal for the currentprocess.Some special devices, called pseudo-devices do notcorrespond to physical devices (e.g. /dev/null).����
  39. 39. Unix filesystem and shell (IV)5.3 RedirectionBefore a command is executed, the input and output can be changed(redirected) from the terminal to a file:Append output:$ ls > file$ date >> file$ cat < fileRedirect standard outRedirect standard in
  40. 40. Unix filesystem and shell (IV)5.4 Mounting file systemsWhen the system starts, the directory treecorresponds to the file system located on a singledisk called the root device.File systems created on other devices are attachedto the original directory hierarchy using the mountmechanism.The commands mount and umount are used tomount and unmount devices.���
  41. 41. Unix filesystem and shell (IV)5.4 Mounting file systems (cont’d)/ab//aabbab//a/bDevice Mount pointroot device external device
  42. 42. Unix filesystem and shell (IV)5.5 LinksA directory is a list of files and directories.Each directory entry links to a file on the disk.Two different directory entries can link to thesame actual file.Moving a file (changing its location) does notactually move any data around.����Creates a link in new location.Deletes link in old location.��In same directory or across different directories.�
  43. 43. 5.5 Links (cont’d)The ln command is used to create a regular link,often called hard link.Symbolic links (soft links) are created using ln -s.The main differences are that:���Hard links don’t work across file system boundaries.Hard links only work for regular files, not directories.��$ ln filename linknameUnix filesystem and shell (IV)
  44. 44. Unix filesystem and shell (IV)5.5 Links (cont’d)Hard vs. symbolic linksdirectoryentryfile contentsdirectoryentrydirectoryentryhard linkhard linksymboliclinkfilecontents
  45. 45. The Unix find command is used to locate files.This will search the whole system for any files named foo anddisplay their pathnames.�$ find / -name fooYou can specify as many places to search as you wish.$ find /tmp /var/tmp . -name fooUnix filesystem and shell (IV)5.6 Find utilitysyntax: find where-to-look what-to-do
  46. 46. Prints an entry for a directory called ./src/misc (if one exists).find . -path ./sr*sc-path pattern�Find every file under the directory /home owned by the user joe.find /home -user joe-user name�Unix filesystem and shell (IV)5.6 Find utility (cont’d)
  47. 47. Search for files which permissions matches the provided expression.find . -perm 664-perm p�Same as previous except that this will ignore presence of any extrapermission bits. This will match a file which has mode 0777, for example.find . -perm -664Unix filesystem and shell (IV)5.6 Find utility (cont’d)
  48. 48. find . -mtime 0 # find files modified between now and 1 day ago# (i.e., within the past 24 hours)find . -mtime -1 # find files modified less than 1 day ago# (i.e., within the past 24 hours, as before)find . -mtime 1 # find files modified between 24 and 48 hours agofind . -mtime +1 # find files modified more than 48 hours agofind . -mmin +5 -mmin -10 # find files modified between# 6 and 9 minutes ago-mmin n -mtime n�Unix filesystem and shell (IV)5.6 Find utility (cont’d)

×