(M)  s i s t e m a   o p e r a c i o n a l   m a g n u x   l i n u x ~/ · documentação · suporte · sobre

  Next Previous Contents

8. Advanced Topics

Here the game gets tough. Learn these features, then you'll be ready to say that you `know something about Linux' ;-)

8.1 Permissions and Ownership

Files and directories have permissions (`protections') and ownership, just like under VMS. If you can't run a program, or can't modify a file, or can't access a directory, it's because you don't have the permission to do so, and/or because the file doesn't belong to you. Let's have a look at the following example:

$ ls -l /bin/ls
-rwxr-xr-x   1 root     bin         27281 Aug 15  1995 /bin/ls*

The first field shows the permissions of the file ls (owner root, group bin). There are three types of ownership: owner, group, and others (similar to VMS owner, group, world), and three types of permissions: read, write (and delete), and execute.

From left to right, - is the file type (- = ordinary file, d = directory, l = link, etc); rwx are the permissions for the file owner (read, write, execute); r-x are the permissions for the group of the file owner (read, execute); r-x are the permissions for all other users (read, execute).

To change a file's permissions:

$ chmod <whoXperm> <file>

where who is u (user, that is owner), g (group), o (other), X is either + or -, perm is r (read), w (write), or x (execute). Examples:

$ chmod u+x file

this sets the execute permission for the file owner. Shortcut: chmod +x file.

$ chmod go-wx file

this removes write and execute permission for everyone except the owner.

$ chmod ugo+rwx file

this gives everyone read, write, and execute permission.

A shorter way to refer to permissions is with numbers: rwxr-xr-x can be expressed as 755 (every letter corresponds to a bit: --- is 0, --x is 1, -w- is 2...).

For a directory, rx means that you can cd to that directory, and w means that you can delete a file in the directory (according to the file's permissions, of course), or the directory itself. All this is only part of the matter---RMP.

To change a file's owner:

$ chown username file

To sum up, a table:

VMS                             Linux                   Notes
------------------------------------------------------------------------------

SET PROT=(O:RW) file.txt        $ chmod u+rw file.txt
                                $ chmod 600 file.txt
SET PROT=(O:RWED,W) file        $ chmod u+rwx file
                                $ chmod 700 file
SET PROT=(O:RWED,W:RE) file     $ chmod 755 file
SET PROT=(O:RW,G:RW,W) file     $ chmod 660 file
SET FILE/OWNER_UIC=JOE file     $ chown joe file
SET DIR/OWNER_UIC=JOE [.dir]    $ chown joe dir/

8.2 Multitasking: Processes and Jobs

More about running programs. There are no `batch queues' under Linux as you're used to; multitasking is handled very differently. Again, this is what the typical command line looks like:

$ command -s1 -s2 ... -sn par1 par2 ... parn < input > output &

where -s1, ..., -sn are the program switches, par1, ..., parn are the program parameters.

Now let's see how multitasking works. Programs, running in foreground or background, are called `processes'.

  • To launch a process in background:
    $ progname [-switches] [parameters] [< input] [> output] &
    [1] 234
    
    the shell tells you what the `job number' (the first digit; see below) and PID (Process IDentifier) of the process are. Each process is identified by its PID.
  • To see how many processes there are:
    $ ps -ax
    
    This will output a list of currently running processes.
  • To kill a process:
    $ kill <PID>
    
    You may need to kill a process when you don't know how to quit it the right way... ;-). Sometimes, a process will only be killed by one of the following:
    $ kill -15 <PID>
    $ kill -9 <PID>
    

In addition to this, the shell allows you to stop or temporarily suspend a process, send a process to background, and bring a process from background to foreground. In this context, processes are called `jobs'.

  • To see how many jobs there are:
    $ jobs
    
    jobs are identified by the numbers the shell gives them, not by their PID.
  • To stop a process running in foreground:
    $ CTRL-C
    
    (it doesn't always work)
  • To suspend a process running in foreground:
    $ CTRL-Z
    
    (ditto)
  • To send a suspended process into background (it becomes a job):
    $ bg <job>
    
  • To bring a job to foreground:
    $ fg <job>
    
  • To kill a job:
    $ kill <%job>
    

8.3 Files, Revisited

More information about files.

  • stdin, stdout, stderr: under UNIX, every system component is treated as if it were a file. Commands and programs get their input from a `file' called stdin (standard input; usually, the keyboard), put their output on a `file' called stdout (usually, the screen), and error messages go to a `file' called stderr (usually, the screen). Using < and > you redirect input and output to a different file. Moreover, >> appends the output to a file instead of overwriting it; 2> redirects error messages (stderr); 2>&1 redirects stderr to stdout, while 1>&2 redirects stdout to stderr. There's a `black hole' called /dev/null: everything redirected to it disappears;
  • wildcards: '*' is almost the same. Usage: * matches all files except the hidden ones; .* matches all hidden files; *.* matches only those that have a '.' in the middle, followed by other characters; p*r matches both `peter' and `piper'; *c* matches both `picked' and `peck'. '%' becomes '?'. There is another wildcard: the []. Usage: [abc]* matches files starting with a, b, c; *[I-N,1,2,3] matches files ending with I, J, K, L, M, N, 1, 2, 3;
  • mv (RENAME) doesn't work for multiple files; that is, mv *.xxx *.yyy won't work;
  • use cp -i and mv -i to be warned when a file is going to be overwritten.

8.4 Print Queues

Your prints are queued, like under VMS. When you issue a print command, you may specify a printer name. Example:

$ lpr file.txt          # this goes to the standard printer
$ lpr -Plaser file.ps   # this goes to the printer named 'laser'

To handle the print queues, you use the following commands:


VMS                                     Linux
------------------------------------------------------------------------------

$ PRINT file.ps                         $ lpr file.ps
$ PRINT/QUEUE=laser file.ps             $ lpr -Plaser file.ps
$ SHOW QUEUE                            $ lpq
$ SHOW QUEUE/QUEUE=laser                $ lpq -Plaser
$ STOP/QUEUE                            $ lprm <item>


Next Previous Contents