RU beehive logo ITEC dept promo banner
ITEC 345
2014fall
ibarland

homelectshws
D2Lbreeze (snow day)

unix-intro
starting unix

============
Intro Unix

  [setup for OS injection: touch, rm, semicolon]
  [note to self:
    ssh ***ibarland@***rucs.radford.edu
    unalias ls
    unalias cd
    setenv TERM xterm
  ]

ls
ls -l
ls -F   
ls -l -F
ls -l Setup
ls -lF Setup

cd Setup
cd Proj12
cd ..
cd ..
cd ..
cd ..

The disk:
   /
   /Users/ibarland

Note: ls /home
  Is this result a security issue?  
    What info is learned, and how could it be used?
    Are there other ways of getting that info?  (Or: getting it as easily?)
  What bout looking *inside* one of these folders -- should I try it?
  [get a student to volunteer their user name and try ls'ing, *then*
   point out that I'm not entirely sure that that was truly their username!]


touch
rm

abs path, vs relative 

shortcuts: ~,   dot-files


Review: 
  Your home dir: ~
  cd (with one arg)
  cd (with no args)
  ls (with several args: both flat files, and directories)
  ls (with no args)
  
  ls ~ dir
  cd

Linux             Windows
  /bin                /System
  /                   C:\
  forward-slash       backslash
  pwd

  /bin   -- "binaries" -- essential commands: ls, cd
  /sbin  -- system commands: mount disks, set up network listeners, ...
  /usr/bin, /usr/sbin -- user-installed binaries (well, anything but the most core linux)
           Not needed for core usability.     e.g. python
  /etc   -- configuration files: /etc/passwords, network connections, ...
  /var/log -- logs are for *accountability*, so every action is recorded
        e.g., if you're the superuser, all superuser commands get logged.
        (... 'course, the superuser can also modify any file, including the log files...)
  /home/ -- user data


==== Two things to always be aware of:
Because you may not get any visual feedback.
- What directory are you currently in?  (matters if you save/want a file w/o using an absolute pathname): `pwd`
- what machine are you running on? --- `hostname`
In both cases, *sometimes* the prompt is set up to help (and if doing a lot of unix stuff, you'll
    want to read about setting the prompt).  From my own .cshrc (csh only -- different for bash!)
```
set  prompt = "%B%m%b %c %h%# "
```
  
  
To find info about valid options, `man`.
   dot-files

ls -a
"hidden" files
.   ..

man man


file permissions

We saw that `ls -l` gives long output: the file-size, and last-modified time. It also gives who the *owner* is, and what *group* the file belongs to. "Groups", in UNIX, are a set of users. For example, on rucs, there is a group "faculty" that I am a member of, but you aren't. If a file is readable by that-group, I can read it, and my colleagues can read it, but student's can't. Similarly, I could as the administrator to create a group called "itec", and to add all students and faculty to that group. If a file were readable by everybody but writeable by the group "itec", then you could change the file, but your friends in Math couldn't (but, they could read the file.) One person can be a member of many groups. However, a single file is associated with just one group (I think?). These days, controlling file-sharing w/ colleagues is often done via google docs, or mailing files back and forth (eck!!). Finally, the intriguing part of the output from `ls -l`: All those r/w/x's! -rw-r--r-- or drwxr-xr-x The first character is either "d" (for directories), or "-" (regular file). That is all. The next nine characters come in chunks of three. Within a chunk, the first character is either "r" (readable ) or "-" (not-readable). the second character is either "w" (writeable) or "-" (not-writeable). the second character is either "x" (xecutable) or "-" (not-xecutable). NOTE: you'll never have (say) an 'r' as the second character in a group-of-three! The three chunks correspond to: - the priviliges granted to the file's *owner* ('u' for 'user') - the priviliges granted to members in the file's *group* - the priviliges granted to *other* users ('o' for 'other') So now, tell me about: -rw-r--r-- and about: drwxr-xr-x NOTE: the special user "root" is the superuser -- they have full permissions to all files, regardless of what the file is set as! ==== Changing a file's permissions What if we look at -rw-r--r-- foo.txt as if it were a binary numeral (ignoring the leading 'directory' bit): 110100100 Breaking that into chunks of three, we can also write it as octal: 110 100 100, or 644 (octal) Q: [Consult with your neighbor, and figure out the answer:] Consider the permissions "readable and executable by user, but just executable by group and other" - What `ls -l` output would that correspond to? - What bit pattern does that correspond to? - What octal numberal does that correspond to? A: - output: r-x --x --x - bit pattern: 101 001 001 (grouped into threes for convenience) - octal: 5 1 1 We can use these "absolute" numbers to change a file's permisions: chmod 511 foo.txt ; ls -l foo.txt -r-x--x--x foo.txt Useful Octal modes to remember: 600, 644, 755 Q: what do each of these mean? When using `chmod` to change file permissions, in addition to giving it an absolute settings (as an octal numeral), we can also change its permissions relative to what it currently is: ls -l foo.txt -r-x--x--x foo.txt chmod u+w foo.txt ; ls -l foo.txt -rwx--x--x foo.txt "u+w" means "add write-permission for user; leave all other permissions the same". Only a file's owner can change that file's permissions, and (of course) the superuser. ==== A note on a *directory's* permissions: Note that "executable" means "can be run as if it's a program", for regular files. (So MS Word would be executable, but someNotes.doc should *not* be executable.) Note that for directories, "r" means "can see the contents of the diretory", and "x" (rather unusually) means "can cd into the directory". "w" means that you can write files *inside* the directory. (Remember, I mentioned in passing that a unix directory is really just a file that contains a list of other filenames plus wehre to find them on disk, and that's why a directory itself can be just 4K even though it holds many lare files? Well, if you think about that fact, it might make it rather clear why r,w,x mean the things they do!) TASK [log on to rucs, and do these, perhaps with a friend to help]: What are the permissions of /etc/motd ? What are the permissions of /etc ? What are the premissions of .cshrc in yoru home directory? Make .cshrc unreadable to group and others (but presevering all other file presmissions). (use relative permissions) Now, change it to be: read/writable by you, and readable by group and other, and no other permissions. (use absolute/octal permissions)

homelectshws
D2Lbreeze (snow day)


©2014, Ian Barland, Radford University
Last modified 2014.Sep.27 (Sat)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.