Files and file systems

Note: A majority of this info comes from my notes of Arthur Griffith's Introduction to Linux

Files and file systems
  • All files (including hard drive, CD-rom, other disk drives from other computers if they are networked, etc.) on a Linux system are found in the directories and sub-directories of the root directory. The root directory is named "Slash" (reeeer). The root is the bottom line! 
From the / ("root") directory, type in "ls" to list the contents of the standard Linux directory.



Directories
A list of the names and locations of files and other directories.
Files can be listed more than once under different names.
Each file (unless it is a link) is connected to an i-node which specifies where the file is.

Creating a new directory
  • mkdr_[NewDirectoryName]
Creating a new link
  • ln_-s_[DirectoryName]_[LinkName] 
    • The "s" means the link is "symbolic"
    • When listed, the LinkName will have an @ at the end
    • DirectoryName and LinkName contain the same file, but only the DirectoryName is real
    • If DirectoryName is removed, LinkName becomes a stand-alone file, but if DirectoryName is re-created, LinkName reverts back to being a link
  • ln_[DirectoryName]_[LinkName]
    • Creates directories of equal footing; they are linked but one is not symbolic; both are real
    • Whatever is changed in one (including deletion) will affect the other
Common types of directories
  • bin = contains executable programs. To list the bin directory contents, type in "ls_bin"
    • The bin files with * at the end are executable commands.
    • The bin files with @ at the end are links, other names for existing files
  • boot = contains the operating system. 
    • Some Linux systems will just dump these files into the root directory, though now more popular to create the boot directory for this purpose.
  • dev = contains files ("device nodes")that connect to the devices in the computer.
  • etc =  contains system configuration files in plain text, including passwd
  • home = contains all the log-in home directory (where users can customize and make "folders," or directories)
  • lib = contains shared, system-wide libraries-- including executables that can be used by more than one computer at the same time.
  • lost+found = where files sometimes appear after Linux tries to repair itself after a crash.
  • MNT = "mount." Other file systems are usually "mounted" in this directory, meaning that all file systems in network can be mounted into this one directory, making all file systems accessible in MNT.
  • opt = this directory was created to house downloaded files; however, in practice, files are often downloaded to other directories with other executables.
  • proc = lets you look inside the running operating system.
    • The directories with #s are running processes
    • The directories with names are locations inside the running kernel
    • You can change some of the info in some of the files-- but only if you know what you're doing!
  • root = home directory of the Super User!! 
    • Like an administrator who has special permissions.
    • If you are the only user, log in as the root and make yourself a user
    • Sometimes you have to log into the Root and become a Super User, but only if you know what you're doing. And even then, log out ASAP!
  • sbin = files and directories used by the Super User. ("Superuser bin.")
  • SWAP = where the operator swaps programs in and out of memory as needed.
  • tmp = used by any program that needs temporary work space.
  • usr = the catch-all directory.
  • var = contain different data files, depending on the program running-- e.g. spool files, data bases.
 
File Permissions
  • Every file has an owner
  • Every file belongs to a group
    • Owner does not have to be a member of the group
  • Every file has a type
    • Besides x, owners and groups can also have permissions set to s. This means that the "set user ID" or "set group ID" is set. The owner and/or the group will need to access the file as if they were the owner. Is often used to allow people to, for example, change their own password.
      • $ chmod +s myfile (changes user execution permission to set ID)
      • $ chmod g+s myfile (changes group execution permission to set ID)
     
    Directory Permissions
    • A "t" in the last (other) place of the directory permissions may be used in place of the x as the "save text attribute" or "sticky bit." This means that only owners of files in this directory can delete files. It's often used in the temp direcotry to prevent users from deleting each others' files.  
      • $chmod +tmydirectory
    • If directories are given the setgid attribute, then all the files in that directory will belong to the group that is set, not the group of the owners who created the files.
      • This could be useful when users from different groups need to work together and/or access files.
    • $ chmod g+s mydirectory
     Default Permissions
    • use the command unmask to set default permissions for file creation.
    • Can use octal (tough for newbies but great once learned): $ unmask 022
    • Or can use symbolic: unmask -S u=rwx


    File system





    The /etc directory
    • /etc/passwd = all the log-ins kept here
      • All logins have the same structure- username : password : unique id number : group number : fullname (free test field) : home/[username] (home directory) : /bin/bash (the program that's run each time a command is imputed)
      • (the password isn't shown here-- just an x; the real password is kept in a shadow file
      • Groups may contain one person or many people
      • Don't make changes! You can lock yourself out. :(
    • /etc/shadow = all the passwords and files that need security kept here. Need to be logged in as super user to be able to access.
      • Fields: username : encrypted password : count of days from 1970 to day password last changed : number of days need to wait before can change password : count of the number of days that will pass before password needs to be changed : days before password expiration that warning will appear : number of days grace to change password after warning appears : date account becomes disabled (if it does)
    • /etc/group =
      • fields = groupname : grouppassword (rarely used) : unique group ID number : can be used to list group members