IT 244 – Chapter 4 The Filesystem: Hierarchical o Root at the top o Directory tree can come off any directory node as subdirectory Files: directory, special, and ordinary o Special files are system level files (symbolic link, device, etc.) o Directories Contain references to any other type of file (directory, special, or ordinary). Are a parent directory to files that it contains, which are its children. A Pathname is a series of directories separated by /. Absolute if the path begins with / or ~. Relative if the path begins with anything else (a directory name, a “.”, or a “..”). o Ordinary files Files that are neither special or directory files are ordinary files created and used by users or programs that users run. o Filenames: A-Z, a-z, 0-9, “_”, “.”, “,” Problems can arise from: Can contain other characters if they are escaped using \. Extensions If a program is built to use a particular extension UNIX does not care about extensions Directories of note: Home directory o Special pathname “~”. ~/ is the current user’s home directory. ~sam/ is the home directory for the user sam. o Special Startup (config) files (beginning with a dot) These files are invisible to ls unless the –a or –A option is given Current directory = “.” Parent directory = “..” Standard system directories: o / - Root o /bin – Essential command binaries o /boot – Files for the system boot loader (all files necessary for boot) o /dev – All device files o /etc – System configuration files /etc/opt – configuration files for some added software /etc/X11 – configuration for the X Window System o /home o o o o o o o o o o o o o /lib – System level shared libraries /lib/modules – Loadable kernel modules (extend the kernel) /mnt – Mount point for temporary filesystems /opt – Add-on software packages (optional) /proc – Kernel and process information /sbin – Essential system binaries utilities for boot process (see /usr/sbin) /tmp /Users – Mac OS X default for user home directories /usr – Contains subdirectories with system-level information /usr/bin – Contains standard Linux and OS X utility programs /usr/lib – Libraries needed by system and many other programs /usr/local – Locally important files for applications added to the system /var – Varying files, such as log, mail, spool, and temporary files. Commands: pwd – Present working directory mkdir [-pv] –m mode] <dirname> – Creates a directory o –p – creates intermediate directories if necessary o –v – verbose creation o –m – set the permissions to <mode> which can be anything acceptable to chmod rmdir – Delete an empty directory cd – Change directory o “cd –“ – toggle between this and the previous directory. touch <filename> - Create an empty file called <filename> mv [-fin] <filename> <newfilename> – Rename a file o If given a new name, this is a simple rename. o If given a new home directory without a new name, this is a move of that file’s inode from being owned by its current directory to the new. o If given a new home directory on a different partition, the file is copied to the new partition, its inode is entered as a child of the new home directory, and then the old file is deleted. o –i – prompt before moving o –f – force no prompt (overrides a previously defined –i) o –n – do not overwrite an existing file (overrides any previously defined –i or –f) cp [-fin] <file> <newfile> – Copy a file o –i – prompt before copying o –f – force the overwrite of an existing file (overrides previously defined –n) o –n – do not overwrite an existing file (overrides previously defined –f or –i) inodes: Fundamental concept on UNIX systems and their descendants An inode is: o A system generated data structure on UFS or ext3 filesystems o The identifier for files containing the actual pointer to the location on disk, and the following associated attributes: Permissions (read, write, execute, suid, sgid, sticky) Owner Group File size File access/change/modification time File deletion time Number of links (soft/hard) Extended attributes Access Control List (ACL) ls –i – shows the inode number for a file (also available with stat) Links: Links are not files, but system structures containing a reference to another file. o They appear as files, having names and being listed by ls o If in the same directory as the linked file, the link must have another name. Useful to share a file or files o In the situation where the shared file(s) should be able to be exchanged for another without having to overwrite the current file/directory. o Indirection: Links can be quickly created and destroyed, thus switching the path to a program’s files (back and forth) seamlessly. Hard links (ln <file> <linkfile>): o Older, and becoming outdated o Restrictions: Can only link to a file that exists in the same partition. Cannot link to a directory. o Basically an instance of the inode of the linked file is added to the directory where the link exists, even if the linked file is in the same directory. o An ls listing shows no difference. Using the –i option, you can see they both have the same inode. o NOTE: if you create a hard link and then remove the original file, the file on disk still exists, accessible through the hard link. Soft (symbolic / symlinks) links (ln [–s | --symbolic] <file> <linkfile>): o Newer, used all the time o An indirect (vs. direct for hard) link to a file A new special file containing the path to the file. o An ls -l listing shows the link permissions starting with an “l”, and an ls –i listing shows two different inodes. o Created to overcome both hard link restrictions o NOTE: if you create a soft link and then remove the original, there is no file to be retrieved. o Added advantage: The ability for a soft link to point to nothing Can remove and replace the file and the soft link still works. o Disadvantage: Unlike hard links, the status information (create, modify, etc.) of the soft link does not reflect that of the linked file. You MUST use full path to the linked file, or there can be problems in retrieving the file through the soft link. If you change directory through a symbolic link with cd, and then do pwd, you will see a totally different path. Removing links: o rm removed links of both types. o Hard links: When you remove the last hard link to a file (including its original hard link from its creation) the file itself will then be deleted. o Soft links: When you remove all soft links to a file the file remains, since the file itself is represented by at least one hard link. Standard Access Permissions: ls –l – “-rwxrwxrwx+” o First position – file type (ordinary, directory, symlink) o Last position – ACL flag o Middle – Permissions - three sections of rwx (user, group, other) chmod [[n]nnn | [ugo][+-][rwxs]] – Change the non-ACL access permissions of a file o Can either use a 3-4 digit permissions setting, or symbolic arguments for adding/removing rwxs for ugo (user,group,other) If s is used, this is for user and group only o If use a 4 digit permission, a binary representation of the leftmost number is used to set SUID, SGID, and sticky bits. SUID = 4 = 100 Represented by a “S” if not executable for user Represented by a “s” if also executable for user SGID = 2 = 010 Represented by a “S” if not executable for group Represented by a “s” is executable for group Sticky = 1 = 001 Represented by a “T” if not executable for other Represented by a “t” if executable for other Bitwise and’ing these together will allow for adding more than one. chown <user> <file> - Change the ownership of the file chgrp <group> <file> - Change the group associated with the file umask <mask> - sets the mask for permissioning in the current session o 777 bitwise or’ed with the mask will be the permissions set by default. ACL Access Permissions: Provide finer-grained control over permissioning Disadvantages: o NOTE: reduces performance – NEVER enable these on a filesystem containing system files o Most utilities do not preserver ACL settings Find out if the utility has an option that you can give on the command line for preserving ACL permissions. mv, cp, tar are good examples. Enabling ACL o Install the acl software package o Linux supports ACL on ext2, ext3, ext4 filesystems. o Mount the disk to be ACL enabled using the acl option in /etc/fstab Remount a disk if the disk was already mounted when /etc/fstab was changed. Can set default rules for permissions of files created within a directory setfacl – Sets a file’s ACL permissions getfacl – Retrieves a file’s ACL permissions