1 / 12

CIT 383: Administrative Scripting

Directories. CIT 383: Administrative Scripting. Topics. Directories Inodes File Management Command Line Arguments. Directories. Directory : table of name to inode mappings $ ls –i / 2272929 bin 65409 boot 49057 cdrom 2260 dev 850305 etc 2 home 2371041 initrd

kipp
Download Presentation

CIT 383: Administrative Scripting

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. Directories CIT 383: Administrative Scripting CIT 383: Administrative Scripting

  2. CIT 383: Administrative Scripting Topics • Directories • Inodes • File Management • Command Line Arguments

  3. CIT 383: Administrative Scripting Directories Directory: table of name to inode mappings $ ls –i / 2272929 bin 65409 boot 49057 cdrom 2260 dev 850305 etc 2 home 2371041 initrd 49075 initrd.img 49058 initrd.img.old 948417 lib

  4. CIT 383: Administrative Scripting Accessing Directories thisdir = Dir.new(pathname) absolutedir = Dir.new(‘/home/smi/dir1’) relativedir = Dir.new(‘smi/dir1’) currentdir = Dir.new(‘.’) uponedir = Dir.new(‘..’) Methods entries: returns array of filenames each: iterates over each file in directory

  5. CIT 383: Administrative Scripting Inodes An inode is a disk structure that contains • Size of the file in bytes. • Device ID that identifies device where file is located. • UID of the file’s owner. • GID of the file’s group. • File mode (permissions.) • Timestamps • ctime: inode change time • mtime: time file content was last modified • atime: time file content was last accessed • Reference count that identifies how many directory entries point to inode. • Pointers to disk blocks containing file data.

  6. CIT 383: Administrative Scripting Hard and Symbolic Links A hard link is • A directory entry that points to an inode. • Deleting a file with rm just removes the directory entry. • File data is not removed until all links removed. A symbolic link is • A file that contains a pathname. • Deleting the link does not affect the file. • Deleting a file with rm invalidates the symbolic link but does not remove it from filesystem.

  7. Basic File Permissions Three sets of permissions: owner, group, world • Each set represented by an octal digit. • Each permission (r,w,x) one bit in octal digit. • Special permissions: setuid, setgid, sticky. ex: chmod 0644 file u: rw, g: r, o: r ex: chmod 0711 bin u: rwx, g: x, o: x CIT 383: Administrative Scripting

  8. CIT 383: Administrative Scripting File::Stat The File::Stat class allows access to inodes stat = File::Stat.new(pathname) OR file = File.new(pathname) stat = file.stat Methods size: size of file in bytes uid: UID of file owner gid: GID of file owner mode: file permissions in octal mtime,ctime,atime: file timestamps

  9. CIT 383: Administrative Scripting Querying File Attributes directory? – Is file a directory? symlink? – Is file a symbolic link? file? – Is file an ordinary file (not a directory, device, or symlink)? readable? – Is file readable by me? writable? – Is file writable by me? executable? – Is file executable by me? setuid? – Is file setuid? setgid? – Is file setgid? sticky? – Is the sticky bit set?

  10. CIT 383: Administrative Scripting File Management The FileUtils class provides methods that emulate the functionality of UNIX commands: chmod chown cp ln mkdir mv rm rmdir

  11. CIT 383: Administrative Scripting Command Line Arguments Using command line arguments ./test.rb arg1 arg2 arg3 Accessing command line arguments Ruby provides them via the ARGV array: ARGV.each do |arg| puts arg end

  12. CIT 383: Administrative Scripting References • Michael Fitzgerald, Learning Ruby, O’Reilly, 2008. • David Flanagan and Yukihiro Matsumoto, The Ruby Programming Language, O’Reilly, 2008. • Hal Fulton, The Ruby Way, 2nd edition, Addison-Wesley, 2007. • Robert C. Martin, Clean Code, Prentice Hall, 2008. • Dave Thomas with Chad Fowler and Andy Hunt, Programming Ruby, 2nd edition, Pragmatic Programmers, 2005.

More Related