Skip to main content

CSC 282.01, Class 05: The Bash shell - a refresher

Overview

  • Preliminaries
    • Notes and news
    • Upcoming work
    • Questions
  • Things you should know about Bash
  • Explorations of those things

News / Etc.

  • Sorry for getting homework out late this week. Life continues to be
    more chaotic than I thought it would be.
  • We should be doing Make next week.

Upcoming Work

Forthcoming

Good things to do

  • Today’s CS Extra on MathLAN
  • Friday Jazz band
  • Friday-Saturday diving - Cheer on Summer White
  • Saturday morning film
  • Sunday swimming
  • All things in moderation

Things you should know about Linux

  • Files and directories
  • Links, soft and hard
  • File and directory permissions
  • I/O redirection
  • Command-line patterns
  • Shell Variables
  • Command-line history
  • The script command

Files and directories

  • Remember: We have storage.
  • Storage is broken into chunks - inodes
  • Files go in those chunks
  • Directories also have to go into chunks
    • Directories list
      • Name, Address of each file and subdirectory
  • inodes must store not just data, but also metadata
    • Maybe file type (can be derived from contents or extension?)
    • Creation time, modification time
    • File size
    • File permissions
  • What happens if you have more data in a file than fits in one inode?
    • Option 1: Linked list of inodes
    • Option 2: Tree of inodes
  • You don’t need to know all of the details, but it helps to think about and remember some of these issues.
  • Yay pointer manipulation
  • ln source target - Hard link, both point to the same inode
  • ln -s source target - Soft link, points to the directory entry
    • Necessary for directories.
    • Different contexts require different choices
  • Example in which soft links are useful
    • vi exam1
    • ln exam1 023123.rkt
    • rsync … exam1 (exam1 gets a new inode)
    • 023132.rkt refers to the old inode
    • ln -s ~/public_html ~/Web
  • Example in which hard links are useful
    • Whoops! I didn’t mean to delete that.

Explore the difference between soft links and hard links by creating a file and hard and soft links to that file. Then try each of the following.

  • Edit the original file and determine which file contents change.
  • Edit the hard-linked alias, and determine which file contents change.
  • Edit the soft-linked alias, and determine which file contents change.
  • Delete the original file and determine what happens if you attempt to look at the other two files.
  • Recreate the original file (same name, different contents) and see what happens to the other two files.
  • Remove the two aliases and re-link for the next steps.
  • Overwrite the contents of each file, using a command like echo "Goodbye" > FILE and then determine which changes affect which files.
  • Summarize what you’ve learned.

If you’ve done that already

  • Explore soft links to soft links
  • Explore soft links to non-existant files
  • Check permissions issues related to these things. What if the original is not readable, but the linked version is?

Conclusion

  • If the contents of the inode changes, we see it through the hard link
  • If the inode associated with the filename changes, we see it through the soft link, but not the hard link.
  • If we rename the file, we can still see it through the hard link, but not the softlink.

Anecdote

  • Even experts get things wrong.
  • Things may have changed.

File and directory permissions

I/O redirection

Command-line patterns

Shell variables

Command-line history

The `script command

  • The [rebelsky@church 501] ~/Web/Courses/CSC282/2017S/_dev/_eboards $ ^C [rebelsky@church 501] ~/Web/Courses/CSC282/2017S/_dev/_eboards $ ^C [rebelsky@church 501] ~/Web/Courses/CSC282/2017S/_dev/_eboards $ ^C [rebelsky@church 501] ~/Web/Courses/CSC282/2017S/_dev/_eboards $ exit Script started, file is typescript Script started, file is typescript Script done, file is typescript command