1 / 36

Chapter 4: The Linux Filesystem

Chapter 4: The Linux Filesystem. Where stuff is. In this chapter …. What is a hierarchical filesystem Directories and files Pathnames: absolute vs. relative Permissions Links. What is a filesystem?. A data structure Stores data Organizes data Allows for data retrieval and manipulation.

ryan-gibson
Download Presentation

Chapter 4: The Linux Filesystem

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. Chapter 4:The Linux Filesystem Where stuff is

  2. In this chapter … • What is a hierarchical filesystem • Directories and files • Pathnames: absolute vs. relative • Permissions • Links

  3. What is a filesystem? • A data structure • Stores data • Organizes data • Allows for data retrieval and manipulation

  4. What is a hierarchical filesystem? • Essentially, a filesystem that allows nesting of folders under a central point • Like a pyramid or upside-down tree • Tree analogy most common – ie the directory tree • Programmers – definition of a tree applies here

  5. Hierarchical Filesystem • Directories can contain other directories and/or ordinary files • Concept different from reality – in implementation everything is a file • Directories, devices, named pipes, ordinary files – all really just files

  6. Lingo • Root directory • Subdirectories • Parents, children

  7. Filenames • Each file within a directory must have a wholly unique filename • Can be up to 255 characters – make them longer to avoid confusion • Special characters must either be escaped out (using backslash) or in quotes • Only illegal characters are / and carriage return

  8. Filenames con’t • Spaces and other special characters a bad idea • Instead of spaces use underscores or periods • Ex: my_file or my.file

  9. Extensions • Not always essential but helps simplify and avoid confusion • Some programs like gcc depend on proper extensions • This includes case!

  10. Hidden Files • To make a file hidden, start it with a period • Ex .plan • A normal ls will not show hidden files • Use ls –a to reveal ALL files • Startup files, containing configuration settings for your account, hidden

  11. mkdir – create directory • Syntax: mkdir directory • Directory can be a relative or absolute pathname (we’ll get to that in a minute) • You can use ls –F to show directories with a forward slash at the end of the name • If using a color terminal, directories will be a different color than ordinary files

  12. Working Directory • The directory you are currently working in • pwd will tell you what your working directory is • Helpful to know when using relative pathnames (again, coming up)

  13. Home Directory • Not to be confused with working directory • The directory you start in when you first logon • Most users it is /home/username • For root, it is /root • Can be changed by system administrator

  14. cd – change working directory • Syntax: cd [directory] • Again, directory can be absolute or relative • If no argument given, changes working directory back to your home directory

  15. Absolute Pathnames (finally) • Absolute pathname for a file gives the file’s location relative to the root of the filesystem • Sometimes long • Ex: /home/jhowell/Assignment1/animals • Shortcut: ~ represents your home directory • So the above could also be ~/Assignment1/animals

  16. Relative Pathanmes • A pathname relative to the current working directory • Make sure you know what your working directory is! • Shorter • Ex, in my home directory: Assignment1/animals

  17. . and .. Directories • . is an alias for the working directory • .. is an alias for the parent of the current working directory • These pointers are placed in every directory when created by mkdir • Can be used in relative pathnames

  18. Standard Filesystem Directories • Most distributions try to adhere to the Filesystem Hierarchy Standards, but it’s not uncommon to find things in odd places • Even less standardized going from Linux to BSD to UNIX • In other words – no guarantees

  19. Common Directories • / (root) – root of the filesystem • /bin – essential system binaries (commands) • /boot – files for the bootloader • /dev – device files • /etc – system configuration files • /home – user home directories • /lib – standard libraries and modules

  20. Common con’t • /mnt – mount point for temporary filesystems (floppies, CD-ROMs, non-native partitions) • /opt – optional add-on software • /proc – kernel and process information • /root – root’s home directory • /sbin – essential system binaries • /tmp – temporary space (not swap)

  21. Common con’t • /usr – common area for data / program users use frequently • /var – frequently changing data like system logs, caches, spools and mailboxes • Lots more important subdirectories – see the textbook

  22. rmdir – remove directory • Syntax rmdir directory • Only deletes empty directories • Not empty? Delete the files with rm and try rmdir again • Lazy? rm –rdirectory will recursively delete a directory and its contents (files and directories) • Use with caution!

  23. touch – create a file • Syntax: touch filename • Creates an empty file (size 0) • Useful to create placeholders or while learning the interface

  24. mv revisited • Already used mv to rename files • If last argument is a directory, mv moves files into a different directory • If given a directory as the first argument, mv moves the directory to the new name supplied (which can either be a rename or move!)

  25. Permissions • Use a ls –l (for long view) and you might see something like this: drwxr-xr-x 2 jhowell jhowell 4096 Aug 18 15:46 Desktop -rw-rw-r-- 1 jhowell jhowell 0 Sep 4 18:08 myfile drwxrwxr-x 2 jhowell jhowell 4096 Aug 22 15:32 public_html filename # of links group Date and time created / accessed File Permissions user size Type of file

  26. File types • - ordinary file • b block device • c character device • d directory • p named pipe • l symbolic link

  27. File permissions • Three types of permissions – read, write and execute • Three sets of permissions – owner (user), group, and other (everyone else) rwx rwx rwx user (owner) other group

  28. chmod – CHange MODe • Changes permissions • Syntax: chmod [ugoa][+-][rwx] • Ex: grant everyone (all) read and writechmod a+rw myfile • Ex: remove execute permission for otherchmod o-x myfile

  29. chmod – alternate syntax • Instead of [ugoa][+-][rwx], use binary equivalent rwx rwx rwx 421 421 421 • For each section, sum up the permissions, and assemble a three digit number • So full access to everyone would be 777

  30. Alternate syntax example • Grant user full access, group read and execute, and deny access to other rwx r-x --- • So we get chmod 750 myfile 0 + 0 + 0 = 0 4 + 2 + 1 = 7 4 + 0 + 1 = 5

  31. Permissions Caveats • To execute a shell script you must allow both read and execute permissions • To get into a directory, you must have execute permission • root can still read and write to files without read and write permissions

  32. One more exception • setuid and setguid • Allows a file to be executed with the permissions of the file’s owner or group • A way to let users perform privileged tasks without granting them general permissions • Should be used sparingly with files owned by root

  33. Links • Pointers to files • Points to an exact location on disk • When a file is created, it is the first link to a particular spot on the disk • To make a file appear in multiple directories, make additional links

  34. Working with Links • Syntax: ln [-s] existing-file new-link • Without –s a hard link is created • With –s a soft or symbolic link is created • To delete a link use rm • Delete all the hard links and the file is ‘deleted’

  35. Hard Links • Points to a precise inode on the disk • Now file appears in two locations • Only one copy of the data is stored • When you create a file, you allocate disk space and create a hard link • Hard links can only be used on a single FS • Can’t link to directories

  36. Soft Links • Also called symbolic links or symlinks • Instead of pointing to inode, points to the pathname of a hard link • Move the original file, symlink breaks • Symlinks don’t touch the data directly – safer • When using lnexisting-file should be an absolute pathname

More Related