Permissions - PowerPoint PPT Presentation

About This Presentation
Title:

Permissions

Description:

chmod 644 = -rw-r--r-- Specify default permissions for all newly created files with ... colours to display different file/directory types as (used by 'ls color' ... – PowerPoint PPT presentation

Number of Views:75
Avg rating:3.0/5.0
Slides: 25
Provided by: MK48
Category:

less

Transcript and Presenter's Notes

Title: Permissions


1
2.0.0.3.2 Introduction to the Shell Session 2
  • Permissions
  • Users and groups
  • Who can do what and how to control it
  • Customizing your environment
  • Changing the shell prompt
  • Aliases
  • Environment variables
  • Saving customizations
  • Pipes and redirection
  • Controlling input and output
  • Running a series of commands
  • Running programs on the command line

2
UNIX Users and Groups
  • Every file/directory belongs to a user and a
    group
  • People logged on to UNIX systems are users
  • Check who you are logged on as with
  • Change who you are logged on as with

whoami
su
3
UNIX Users and Groups
  • Check which groups you belong to with
  • See what user and group a file belongs to with ls
    l or stat (as in 2.0.0.3.1)

groups
Group
User
Group users Every user at GSC belongs to the
group users, and this is the default group
ownership for any file created.
4
UNIX Users and Groups chgrp
  • Users (except root) cannot change which user owns
    a file
  • Change the group that a file (or directory)
    belongs to with
  • -R change recursively (all subdirectories and
    files)

chgrp
5
The Permissions System reading, writing, and
executing
  • Permissions refer to the type of access that
    users have to files
  • Allows files to be private, public, read-only,
    etc.
  • There are three types of access possible
  • Read (ability to see the contents of a file, or
    list the contents of a directory)
  • Write (ability to modify or delete a file, or
    create files in a directory)
  • Execute (ability to run the file as a program
    eg. Perl scripts need to be executable or enter
    a directory)
  • Permissions are set individually for
  • User
  • Group
  • All users

6
The Permissions System reading, writing, and
executing
  • Read, write, and execute permissions for user,
    group, and all users are specified as r, w
    and x (if the permission is given) or - (if
    the permission is denied)

For all users
For group
For user
7
Changing Permissions chmod
  • If you own a file, change permissions using
  • Specify

chmod
chmod ugoa-rwx
Other options -R apply recursively
Who to modify permissions for u user g
group o other (all users) a all (u,g, and o)
Whether to give or take permission give -
take away these are the only permissions
What permission to modify r read w write x
execute
8
Changing Permissions chmod examples
  • Make a file private (only you can see it)
    -rw-------
  • chmod og-rw or chmod og
  • Make a file public (everyone can modify it)
    -rw-rw-rw-
  • chmod arw
  • Make a directory private (only you can view its
    contents) drwx------
  • chmod og-rwx or chmod og
  • Make a directory usable by anyone (anyone can add
    files to it) drwxrwxrwx
  • chmod arwx
  • Make a file executable -rwxr-xr-x
  • chmod ax

9
Changing Permissions chmod and umask
  • You can also use a set of numbers to set
    permissions
  • Specify default permissions for all newly created
    files with

umask
http//www.cs.ualberta.ca/doc/UNIX/novice-unix-doc
/permissions.html
eg. umask 022 -rw-r--r (files)
-rwxr-xr-x (directories)
eg. chmod 644 -rw-r--r--
10
Other file attributes chattr
  • In addition to specifying permissions, other file
    attributes can be set with
  • eg. set the file so it cannot be deleted, so its
    access time is not updated, or so that it is
    stored in compressed form.

chattr
11
Customizing your Environment Environment
variables
  • Environment variables store information about how
    your shell should look and behave, where to find
    things, particular program settings, etc. They
    are used by programs running in the shell.
  • See what environment variables are currently set
    with
  • Set environment variables with
  • ltVARIABLEgtnew value
  • Delete environment variables with

printenv
unset
12
Setting the Prompt PS1
  • Get colourful! To specify colour, bracket the
    colour code between a \e (or \033) and an
    m
  • 30 Black
  • 31 Red
  • 32 Green
  • 33 Yellow
  • 34 Dark blue
  • 35 Purple
  • 36 Light blue
  • 37 White
  • The environment variable PS1 stores what is
    displayed at the prompt
  • Use special characters
  • \d date
  • \t and \_at_ time
  • \h hostname
  • \u username
  • \w current directory

Word wrapping isnt working! When modifying
colours in PS1, surround the color specifications
with \ and \ to tell the shell that text
doesnt take up any space on the prompt.
13
Specifying Where to Look for Programs PATH
  • The PATH variable stores a list of directories
    where the shell and other processes should look
    for programs
  • Each entry is separated by
  • Start your path with . to run scripts without
    specifying ./

14
Specifying Where to Look for Directories CDPATH
  • CDPATH is like PATH, but instead of specifying
    where to look for programs, it specifies where to
    look for directories
  • Be careful, it can be dangerous. always put .
    first!

15
Other Environment Variables
  • HISTSIZE specifies the number of commands to keep
    in the history
  • PRINTER specifies the printer name
  • PWD stores the current directory (used by pwd)
  • OLDPWD stores the previous directory (used by cd
    )
  • LS_COLORS specifies colours to display different
    file/directory types as (used by ls color)
  • Various programs require other environment
    variables
  • BLAST
  • SRS
  • Java
  • Perl
  • Etc.

16
Defining Commands aliases
  • An alias is a short form of a command that can
    save on typing
  • View and assign aliases with
  • To use the normal command, not the alias, use
  • \ltcommandgt
  • eg. \ls lists with no colour etc.

alias
17
Customizing your Environment Configuration at
startup
  • Customizations are lost when you logout
  • To save them, put them in one of your
    configuration files
  • .bash_profile (/home/ltusergt/.bash_profile) is run
    every time you log on
  • .bashrc (/home/ltusergt/.bashrc) is run every time
    you open a shell other than the login shell
  • export the variables so you can see and access
    them
  • Oops!
  • Careful. If you do something wrong (like make
    text white on white) it can be difficult to fix
  • Test everything before putting it in .bashrc or
    .bash_profile
  • Keep an extra terminal window that was opened
    BEFORE you made the changes, so you can use that
    terminal to fix mistakes

18
Input, Output, and Error
  • Data can be transferred (eg. between commands) in
    the shell using three streams
  • Standard input (STDIN in Perl) Input to a
    process, by default from the keyboard
  • Standard output (STDOUT in Perl) Output from a
    process, by default to the terminal window
  • Standard error (STDERR in Perl) Another stream
    of output from a process, by default to the
    terminal window
  • eg.
  • cat takes a file or text from the terminal as
    standard input, writes the file contents to
    standard output (the terminal)
  • Error messages from commands are written to
    standard error
  • Perl scripts by default write to standard output

19
Redirecting Input, Output, and Error gt, lt, gtgt,
2gt, gt
append stdout
  • Redirect standard input to a file with lt
  • Redirect standard output to a file with gt or 1gt
  • Redirect standard error to a file with 2gt
  • Redirect BOTH standard output and error to a file
    with gt
  • Redirect standard output to append to a file with
    gtgt

stdout
stderr
/dev/null A useful file to redirect to is
/dev/null anything redirected here just
disappears. Good for programs that produce a lot
of verbose messages that you dont need to see or
keep.
20
Example Perl output
  • It is good practice to separate real output
    from error messages when running Perl scripts

21
Running a Series of Commands pipes
  • To put the standard output of one command
    directly into the standard input of another, use
    a pipe (on the keyboard above the \)
  • You can do this as many times as you like on one
    line especially useful for command line tools
    like grep, cut, sort, wc, etc. (see session
    2.0.0.3.3)

22
Running Programs on the Command Line
  • With correctly set environment variables and
    ability to redirect output, you will find it much
    easier to run command-line programs (eg. BLAST)
  • To check where a program is installed, use
  • If the command is in your PATH, the shell will
    tell you where it is
  • Important to check when there is more than one
    version of the program installed (eg. Perl at
    GSC!)

which
Getting help Many programs will give short help
messages when run without any parameters (eg.
perl, blastall). Otherwise, try option h or
--help. To check the program version, try
--version.
23
2.0.0.3.2 Introduction to the Shell Session 2
  • Now you know.
  • How to see and set permissions
  • How to customize your environment, and save
    customizations for future sessions
  • How to control input and output, and run a series
    of commands
  • Next youll learn.
  • Job control
  • Command line goodies (really useful tools)
  • Command line Perl

24
2.0.0.3.2 Further Readings
  • Permissions
  • Linux Cookbook Ch. 7
  • Learning the UNIX Operating System Ch. 3.3
  • Customizing the shell
  • Linux Cookbook Ch. 4.6
  • Learning the UNIX Operating System Ch. 3.6
  • PS1 http//www-106.ibm.com/developerworks/linux/l
    ibrary/l-tip-prompt/
  • Redirecting input and output
  • Linux Cookbook Ch. 4.2
  • Learning the UNIX Operating System Ch. 5
Write a Comment
User Comments (0)
About PowerShow.com