Top

A Linux User Reference

Search tips
  • search ignores words that are less than 4 characters in length
  • searches are case insensitve
  • if a search does not return anything try it in Boolean mode then Query expansion mode by checking the appropriate radio button e.g. searching for 'cron' in just the Administration category returns nothing - presumably because the 50% threshold is reached. Boolean mode ignores this threshold so a search for 'cron' returns several hits
  • in Boolean mode preceding a word with a '+' means the result must include that word, a '-' means it must not
  • in Boolean mode '+crontab -anacron' means match articles about crontab that DO NOT mention anacron
  • to match a phrase e.g. 'manage system' check the Boolean mode radio button and enclose the phrase in quotes "some phrase ..."
  • in Query expansion mode the search context is expanded beyond the keywords you entered - relevancy of hits may well be degraded

ADMINISTRATION

Printing

  • Common printing components

    BSD has largely been dropped due to the over use of root SUID. Two more competing implementations:

    LPRng

    A rewrite of BSD without the reliance of root SUID

    CUPS

    Common Unix Printing System

    lpd

    Non-CUPS printer daemon, it starts at boot, listens for requests directed at multiple printers. lpd forks itself per print queue, each copy exiting when all requests in its queue are done. Always one lpd daemon, several if several queues contain requests.

    Filters

    Used when a printer cannot directly render a job. Filters are software which transforms the original data to something the printer can understand.

    /etc/printcap

    Printer names, params and rules used by lpd when spooling print jobs.

    /var/spool/lpd/

    Spool directories to spool requests, local and remote.

    /var/spool/cups

    Directory for spooling. Usually set up correctly when you install CUPS. Spool directories and files should have permissions set to protect them from being read or written by users other than the printing system.

    /etc/cups

    Location of configuration files.

  • CUPS server configuration
    /etc/cups/cupsd.conf

    CUPS server 'cupsd' runs under the control of a configuration file - usually /etc/cups/cupsd.conf. This file controls such things as access to the printing system, whether remote printing is allowed, location of spool files and so on.

    Sample cupsd.conf

    # Log general information in error_log - change "info" to "debug" for troubleshooting...
    LogLevel info
    
    # Administrator user group...
    SystemGroup sys root
    
    # Only listen for connections from the local machine.
    Listen localhost:631
    Listen /var/run/cups/cups.sock
    
    # Show shared printers on the local network.
    Browsing On
    BrowseOrder allow,deny
    
    # (Change @LOCAL to ALL if using directed broadcasts from another subnet.)
    BrowseAllow @LOCAL
    
    # Default authentication type, when authentication is required...
    DefaultAuthType Basic
    
    # Restrict access to the server...
    <Location />
      Order allow,deny
      Allow localhost
    </Location>
    

    The Common Unix Printing System (CUPS) server daemon is '/usr/sbin/cupsd'. Log files in /var/log/cupsd.

    Default log files

    -rw-------  1 root lp   133648 2007-11-18 12:26 access_log
    -rw-------  1 root lp    37554 2007-11-18 12:35 error_log
    -rw-------  1 root lp     1176 2007-11-14 19:07 page_log
    
  • CUPS
    Stopping and starting

    CUPS is usually started during system initialisation. Can be run from the cmd-line, may be controlled by the CUPS script located in /etc/rc.d/init.d or /etc/init.d.

    CUPS 'init.d script name' will vary depending on the distribution and version

    (Debian/Ubuntu)
    /etc/init.d/cupsys {start|stop|restart|force-reload|status}        or
    /etc/init.d/cups   {start|stop|restart|force-reload|status}  
    
    (Fedora/RedHat)
    /etc/init.d/cupsd  {start|stop|restart|force-reload|status}        
    

    Stop and start CUPS

    $ sudo killall cupsd
    [sudo] password for mark:
    
    $ ps -ef | grep cups
    mark     21738  4260  0 14:37 pts/0    00:00:00 grep cups
    
    $ sudo /etc/init.d/cups start
     * Starting Common Unix Printing System: cupsd                          [OK]
    

    Can also be stopped in the 'usual' linux ways, 'kill ' and via 'init.d scripts'.

  • Printer capabilities file
    /etc/printcap

    This file is generated automatically by CUPS, needs to be done manually for BSD and System V.

    Sample BSD, System V configuration - /etc/printcap

    # My comments within ( ... ) are just that - not part of the file
    
    Stylus_C46|Epson Stylus C46:
        :sd=/var/spool/lpd/Stylus_C46:        (Spool directory)
        :mx#0:                                (Max size of a print job (blocks).  #0=no limit)
        :sh:                                  (Suppress header pagers)
        :lp=/dev/lp0:                         (Printer device)
        :if=/var/spool/lpd/lp/filter:          (Input_filter)
        :lf=/var/log/lpd/lp/log:               (Log file)
    Remote C46| rlp:
        :sd=/var/spool/lpd/rlp:               (Local spool directory for remote printer)
        :rm=lphost:                           (Remote machine)
        :rp=rlp:                              (Remote printer)
        :mx#0:
        :sh:
        :if=/usr/local/bin/magicfilter
    

    A single printer definition can have multiple names (aliases). Multiple print definitions can refer to the same Printer.

    Sample CUPS configuration - /etc/printcap

    # This file was automatically generated by cupsd(8) from the /etc/cups/printers.conf file.
    # All changes to this file will be lost.
    # <name> <printer description> <rm=remote machine> <rp=remote printer>
    Stylus_C46|Epson Stylus C46 Foomatic/gutenprint-ijs-simplified.5.0:
    rm=localhost.localdomain:rp=Stylus_C46:
    

    A single printer definition can have multiple names (aliases). Multiple print definitions can refer to the same Printer.

  • Sample CUPS
    /etc/cups/printers.conf

    Defines the local printers that are available. It is generated automatically 'cupsd' when printers are added or deleted.

    Sample (truncated) entries for printers.conf

    <Printer DCP375CW>                                            
    UUID urn:uuid:6403c04b-1aee-394e-405b-027f4c080e15
    Info DCP375CW
    Location Local lan
    MakeModel Brother DCP-375CW CUPS
    DeviceURI dnssd://Brother%20DCP-375CW._pdl-datastream._tcp.local/
    State Idle
    .....
    </Printer>
    
    <DefaultPrinter PDF>
    Info Localprinter
    Location Attached
    DeviceURI usb://EPSON/Stylus%20DX7400
    State Stopped
    StateMessage Unplugged or turned off
    .....
    </Printer>
    

    The first printer is a networked printer

  • Configure a printer via the cmd-line

    Check printers and add a new one

    # lpstat -t
    Scheduler is running
    System default destination: Stylus_C46
    Device for Stylus_C46: usb://EPSON/Stylus%20C46
    Stylus_C46 accepting requests since Sun 18 Nov 2007 03:07:18 PM GMT
    Printer Stylus_C46 is idle.  enabled since Sun 18 Nov 2007 03:07:18 PM GMT
    
    # lpadmin -p Stylus-2 -E -P "/usr/lib/cups/filter/foomatic-rip" -v      \         (add the new printer)
    "usb://EPSON/Stylus%20C46" -D "mark 2"
    
    # lpstat -t
    Scheduler is running
    System default destination: Stylus_C46
    Device for Stylus-2: usb://EPSON/Stylus%20C46
    Device for Stylus_C46: usb://EPSON/Stylus%20C46
    Stylus-2 accepting requests since Sun 18 Nov 2007 04:44:06 PM GMT
    Stylus_C46 accepting requests since Sun 18 Nov 2007 03:07:18 PM GMT
    Printer Stylus-2 is idle.  enabled since Sun 18 Nov 2007 04:44:06 PM GMT 
    Printer Stylus_C46 is idle.  enabled since Sun 18 Nov 2007 03:07:18 PM GMT
    
  • Print filters
    MIME

    CUPS uses MIME (Multi-purpose Internet Mail Extensions) types to determine the appropriate conversion filter when printing a file. Other printing packages may use the magic number mechanism as used by the file command.

    If using LPD, LPRng or another printing system they may well use either magicfilter or apsfilter for converting input files to PostScript format and will probably use Ghostscript as the printer driver for non-PostScript printers. In such a case the filtering process starts with

    • -> raw data file (txt, html, ps, graphics etc.)
    • -> PostScript
    • -> Ghostscript
    • -> Printer

    Configuration for printers and filters will be in /etc/printcap.

    If a suitable filter cannot be found, an attempt to print a file will result in an error message. If using a printer daemon other than CUPS you may get unexpected output instead.

    Some sample entries - /etc/cups/mime.convs

    # PostScript filters
    application/pdf           application/postscript  33            pdftops
    application/postscript    application/vnd.cups-postscript 66    pstops
    application/vnd.hp-HPGL   application/postscript  66            hpgltops
    application/x-cshell      application/postscript  33            texttops
    application/x-csource     application/postscript  33            texttops
    application/x-perl        application/postscript  33            texttops
    .....
    
  • Printer commands

    In general most commands are BSD, SYSTEM V and CUPS compatible though not all options are valid.

    CUPS allows printer names to contain any printable character except SPACE, TAB, "/", or "#". Printer and class names are not case-sensitive.

  • Print printer status information
    /usr/bin/lpstat

    Print CUPS, BSD and System V printer status information. Loads of options.

    Show all status information

    # lpstat -t
    Scheduler is running
    System default destination: Stylus_C46
    Device for Stylus_C46: usb://EPSON/Stylus%20C46
    Stylus_C46 accepting requests since Sun 18 Nov 2007 01:36:58 PM GMT
    Printer Stylus_C46 now printing Stylus_C46-9. enabled since Sun 18 Nov 2007 01:36:58 PM GMT
            Printer not connected; will retry in 30 seconds...
    Stylus_C46-7      root       2048   Sun 18 Nov 2007 01:36:58 PM GMT
    Stylus_C46-8      root       2048   Sun 18 Nov 2007 01:37:28 PM GMT
    Stylus_C46-9      mark       1024   Sun 18 Nov 2007 01:38:14 PM GMT
    

    Show user mark's queued print jobs

    # lpstat -U mark
    Stylus_C46-9      mark        1024   Sun 18 Nov 2007 01:38:14 PM GMT
    
  • Display printer queue status
    /usr/bin/lpq

    Show print queue for CUPS class printer(s)

    # lpq CUPS
    Stylus_C46 is ready and printing
    Rank    Owner   Job     File(s)           Total Size
    active  root    7       passwd            2048 bytes
    1st     root    8       passwd            2048 bytes
    2nd     mark    9       .bash_profile     1024 bytes
    
  • Enable, disable printer queue(s)
    /usr/sbin/accept, reject

    Get queue name, disable it then re-enable it

    $ lpstat -a
    DCP375CW accepting requests since Tue 15 Oct 2013 15:11:08 BST
    
    $ reject DCP375CW
    $ lpstat -a
    DCP375CW not accepting requests since Tue 15 Oct 2013 15:11:08 BST -
        Rejecting Jobs
    
    $ accept DCP375CW
    $ lpstat -a
    DCP375CW accepting requests since Tue 15 Oct 2013 15:11:08 BST
    

    Disable printer Stylus_C46's print queue

    # reject STylus_C46                  (NB. Note queue is not case-sensitive)
    

    Check the queue status

    # lpc status
    Stylus_C46:
        printer is on device usb speed -1
        queuing is disabled
        printing is disabled             (Disabled with earlier command - cupsdisable)
        3 entries
        daemon present
    
    # lpstat -p -a
    Printer Stylus_C46 disabled since Sun 18 Nov 2007 01:43:22 PM GMT -
        Rejecting Jobs
    Stylus_C46 not accepting requests since Sun 18 Nov 2007 01:43:22 PM GMT -
         Rejecting Jobs
    
  • Non CUPS printers and printer queues
    /usr/sbin/lpc

    Provides limited control over CUPS printer and class queues via an interactive interface if no commands are provided on the cmd-line. 'lpc' CANNOT fully manage CUPS use lpadmin.

    Display status information on all configured printers

    # lpc status
    Stylus_C46:
        printer is on device usb speed -1
        queuing is enabled
        printing is enabled
        no entries
        daemon present
    

    Run 'lpc' interactively

    # lpc
    lpc> help
    Commands may be abbreviated.  Commands are:
     (CUPS and BSD, System V compatible)
     exit    help    quit    status  ?
     (BSD, System V only)
     abort {all|printer}                Terminates printing immediately, even half way thro' a job.
                                        Job is retained, will restart when printer restarts.
     disable {all|printer}              Disables the queue, printing continues but no new requests
                                        except for root.
     enable {all|printer}               Enable queues.
    .....
    lpc> status
    Stylus_C46:
        printer is on device usb speed -1
        .....
    lpc> quit
    
  • Cancel, delete a queued print job
    /usr/bin/lprm

    BSD, CUPS or SYSTEM V.

    Cancel all jobs

    # lprm -
    

    Cancel by job id

    # lprm <jobid1>, <job id2>, <job id3>, ...
    
  • Print a file or alter a pending job
    /usr/bin/lp

    Submits files for printing or alters a pending job. Pretty much the same options as 'lpr'.

    See what's in the queue

    # lpq -l
    Stylus_C46 is not ready
    Root: 1st   [job 7 localhost]    passwd          2048 bytes
    Root: 2nd   [job 8 localhost]    passwd          2048 bytes
    Mark: 3rd   [job 10 localhost]   .bash_profile   1024 bytes
    

    Promote my job - id=10 and print 2 copies

    # lp -i 10 -n 2 -q 100
    
    # lpq -l
    Stylus_C46 is not ready
    Mark: 1st   [job 10 localhost]   2 copies of .bash_profile   1024 bytes
    Root: 2nd   [job 7 localhost]    passwd                      2048 bytes
    Root: 3rd   [job 8 localhost]    passwd                      2048 bytes
    
  • Move a queued job(s)
    /usr/sbin/lpmove

    Moves the specified job or all jobs from source to destination. Job can be the job ID number or the old destination (source) and job ID (separated by a '-').

    Move job 123 from default printer to newprinter

    # lpmove 123 newprinter
                                             (or)
    # lpmove oldprinter-123 newprinter       ('old destination'-'job id')
    
  • Enable, disable CUPS printers
    /usr/sbin/cupsenable, cupsdisable

    Disable then re-enable printer Stylus_C46

    # cupsdisable Stylus_C46
    # cupsenable Stylus_C46
    

    Printer names, labels are case sensitive.

  • Configure CUPS printers and classes
    /usr/sbin/lpadmin

    Can also use the GUI in browser - http://localhost:631 or http://127.0.0.1:631.

    Lots of options – see man pages.

  • Display, set printer options
    /usr/bin/lpoptions

    CUPS only. See man pages for more details. Two files -

    ~/.CUPS/lpoptions

    User defaults and instances created by non-root users.

    /etc/cupsd/lpoptions

    System-wide defaults and instances created by the root user.

    Display current options

    $ lpoptions -l
    .....
    BrPhoto2L_B Postcard BrHagaki_B DoublePostcardRotated EnvC5 EnvDL Env10 EnvMonarch EnvYou4
    BRResolution/Quality: 150x150dpi 300x300dpi *600x600dpi 1200x1200dpi 1200x2400dpi 1200x6000dpi
    BRMonoColor/Color/Grayscale: *Color Mono
    .....
    
  • Print one or more files
    /usr/bin/lpr

    Loads of options, can do a lot of things.

  • Print multiple pages on a single page
    /usr/bin/mpage

    Not always available. Manipulates text size (plain text or PostScript) to fit multiple print pages on a single sheet.

    mpage [options] file(s)
    
  • Some postscript utilities
    psnup, a2ps, psbook
    a2ps

    Convert FILE(s) or standard input to PostScript

    psnup

    Performs similar functions for PostScript files as mpage does for text files

    psbook

    Rearranges the pages of a PostScript document for printing as a book or booklet, taking into account the number of pages per sheet and how the sheet is folded