2 Hierarchy Standard File Hierarchy Standard (FHS) Defines a standard set of directories for use by all Linux and UNIX systems.
3 /bin contains binary commands for use by all users. /boot linux kernel and boot info/dev device files/etc system specific configuration files/home User home directories/lib shared program libraries/mnt empty – use for accessing fd0 cd/opt additional software programs/proc process and kernel info/root root’s home directory/sbin system binary commands (admin)/tmp temp files
4 /usr most system commands and utilities /usr/bin user binary commands/usr/games educational prog and games/usr/include C program header files/usr/lib libraries/usr/local local programs/usr/share files that are architecture indpt/usr/src source code/usr/X11R6 the Xwindow system/usr/local Location for most add programs
5 Navigating Commands: pwd current path ls –F man ls for extra flag optionsmkdir creates a new directorymv cps and moves filescp cps filesAliases are special variables in memory that point to commands
6 Navigating Cont’d rmdir or rm removes files or directories rmdir only if directory is empty use rm –rf to remove filled directory and force its completion.Finding files:locate first time use updatedb to create structure databasefind
7 Understanding PATH Special variable echo $PATH Most executable files stored in /bin or /sbinScattered over 20 bin and sbin directoriesEnsure that users don’t have to provide full path names to all commands like lsExists this special variable that is placed into memory each time a user logs into the Linux system.
8 PATH Cont’dPATH variable lists dir’s that are searched for executable files if a relative or absolute pathname was not specified.User types lsSystem recognizes not an absolute pathnameLooks for ls executable which is found in /bin with other commandsUse which command to for location – which grep
9 Linking Files Files may be linked in two ways One file may be simply a pointer or a shortcut (symbolic link)Or two files may share the same data (hard link)To understand linking must know how files are stored on this filesystem.
10 On a structured level, a filesystem has three main sections: The superblockThe inode tableData blocks
11 SuperblockContains info about the filesystem in general, such as number of inodes or data blocksAlso how much data a data block stores in KB’s
12 inode Table Consists of several inodes(information inodes); Each inode describes one file or directory on the filesystemContains unique inode # for identificationMost imp – inode stores info such as the file size, data block locations, last modified date, perms, and ownership.
13 Data BlocksThe data that makes up the contents of the file as well as the filename are stored in data blocks.They are referenced by the inode.Blocks are known as allocation units because they are the unit by which disk space is allocated for storage.
14 Hard Linked filesAre direct copies of one another, as they share same inode and inode #.All files are same size, when one is modified the other is updated as well.You can hard-link a file an unlimited number of times, however all must reside on the same filesystem.Create a hard-link using the ln command.
15 ln command Exp: file1 file2 – need to be linked Use ln file1 file2 Creates the file 2 and links to file1 both have same inode #Deleting a hard-linked file does not delete all the other ln’d files
16 Symbolic LinkDifferent from hard-linked because do not share same inode and inode # with their target file.Merely a pointer to the other and thus both files have different sizes.Data blocks contain only the pathname to the target file.Editing a sym linked file you are actually editing the target file.Thus if target file is deleted, then the sym link servers no function.
17 File / Directory Perms Whoami command shows who you are logged in as Groups command – what groups you belong tochown change ownership of files / dir’schgrp change groupschmod change file mode
18 ModeSection of inode that stores permissions is called mode of the file and is divided into three sections based on the user’s that rec the perms to the file or dir.User (owner) permsGroup (group owner) permsOther (everyone else on Linux system) perms
19 Mode rwxrwxrwx rwx read write execute Also three regular permissions:ReadWriteExecuterwxrwxrwxrwx read write executeFirst 3 User, next 3 group next other
20 drwx------ 3 root root 4096 Apr 8 07:12 Desktop User has r/w/x for owner root and this is a dir.Read – allows user to open / read the contents of a fileWrite – Allows user to open/read/edit contentsExecute – Allows user to execute the file in memory and shell scripts
21 Imp not to give x perms to files that are not programs or shell scripts. Ensures that files will not be x’d accidentally causing the shell to try to interpret its contents.
22 Changing perms Use chmod two methods: u(user) + adds perm r(read) g(group - removes perm w(writeo(other) = equal x(execute)a(all cats)Org file perms –r---w---xChange file from rw-r--r-- must add write perms to the user, add read perms and take away w for group and add read and take away x for other
23 So…chmod u+w,g+r-w,o+r-x file1 Remember ugoaOr use = criteriachmod u=rw,g=r,o=r file1Or use a if perms to be changed are identical for user, group and otherchmod a+x file1
24 Other MethodAll perms are stored in the inode of a file or directory as binary powers of two:Read = 2^2 = 4Write = 2^1 = 2Execute = 2^0 = 1Thus rwxrwxrwx is
26 Exp:r-xr----- use chmod 540 file1rw-r--r--use chmod 644 file1
27 Special Perms SUID (Set user ID) SGID (Set group ID) Sticky bit SUID – has no special function when set on a directory, however if set on a file and the file is executed, then the person who executed the file temp becomes the owner of the file.
28 For exp: ping command – used test network connectivity For exp: ping command – used test network connectivity. Person executing becomes temp owner.Ensures that specific root owned commands will be able to be used by other users.SUID can only be applied to binary compiled programs.Cannot be applied to shell scripts – security hazard.
29 SGID Has a function when applied to both files and dir’s. Allows reg users to execute binary compiled programs and become a member of the group attached to that file.When placed on a directory, user creates a file if SGID perms set – user’s name will still become the owner but directories group will become the group of the file.
30 Sticky bit Used in the past on files to lock them in memory. Today – Assists in setup of common directories – recall that if a write perm is applied to a dir – allows one to add and remove files – thus one could still delete all the files in that dir.If sticky bit is applied to common dir then employees may add files but only delete those files that they have added not others.