Linux Linux File System
Hierarchy Standard File Hierarchy Standard (FHS) Defines a standard set of directories for use by all Linux and UNIX systems. www.pathname.com/fhs
/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
/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
Navigating Commands: pwd current path ls –F man ls for extra flag options mkdir creates a new directory mv cps and moves files cp cps files Aliases are special variables in memory that point to commands
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 database find
Understanding PATH Special variable echo $PATH Most executable files stored in /bin or /sbin Scattered over 20 bin and sbin directories Ensure that users don’t have to provide full path names to all commands like ls Exists this special variable that is placed into memory each time a user logs into the Linux system.
PATH Cont’d PATH variable lists dir’s that are searched for executable files if a relative or absolute pathname was not specified. User types ls System recognizes not an absolute pathname Looks for ls executable which is found in /bin with other commands Use which command to for location – which grep
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.
On a structured level, a filesystem has three main sections: The superblock The inode table Data blocks
Superblock Contains info about the filesystem in general, such as number of inodes or data blocks Also how much data a data block stores in KB’s
inode Table Consists of several inodes(information inodes); Each inode describes one file or directory on the filesystem Contains unique inode # for identification Most imp – inode stores info such as the file size, data block locations, last modified date, perms, and ownership.
Data Blocks The 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.
Hard Linked files Are 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.
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
Symbolic Link Different 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.
File / Directory Perms Whoami command shows who you are logged in as Groups command – what groups you belong to chown change ownership of files / dir’s chgrp change groups chmod change file mode
Mode Section 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) perms Group (group owner) perms Other (everyone else on Linux system) perms
Mode rwxrwxrwx rwx read write execute Also three regular permissions: Read Write Execute rwxrwxrwx rwx read write execute First 3 User, next 3 group next other
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 file Write – Allows user to open/read/edit contents Execute – Allows user to execute the file in memory and shell scripts
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.
Changing perms Use chmod two methods: u(user) + adds perm r(read) g(group - removes perm w(write o(other) = equal x(execute) a(all cats) Org file perms –r---w---x Change 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
So…chmod u+w,g+r-w,o+r-x file1 Remember ugoa Or use = criteria chmod u=rw,g=r,o=r file1 Or use a if perms to be changed are identical for user, group and other chmod a+x file1
Other Method All perms are stored in the inode of a file or directory as binary powers of two: Read = 2^2 = 4 Write = 2^1 = 2 Execute = 2^0 = 1 Thus rwxrwxrwx is 421421421
rwx 4+2+1 = 7 rw- 4+2=6 r-x 4+1=5 r-- 4 -wx 2+1=3 -w- 2 --x 1 --- 0
Exp: r-xr----- use chmod 540 file1 rw-r--r--use chmod 644 file1
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.
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.
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.
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.