Help hurricane victims by donating to the American Red Cross.

System Admin tips

From Ollie's Web Site

Contents

System Administrator Notes

This page contains various notes and howto's (micro) on assorted linux commands and programs.

Use search to find content.


archives

  • cat file1 file2 | gzip > foo.gz
   concatenates file1 and file2, then compresses and saves as foo.gz.
  • gzip <files> zips in place
  • gunzip <files> unzips in place
  • tar --create --file=fn.tar -v files
   creates tar and adds files
   short form: tar -cvf tar files
  
  • tar {--append | -r} --file=fn.tar
   appends file(s) to named tar
  • tar -xvf tarfile.tar
   extracts verbose files from tar

Examples:

  • tar -cvf /dev/rmt0 /bin /usr/bin
   archives contents of /bin and /usr/bin (verbose) to tape drive
  • tar tvf /dev/rmt0
   list the tape's contents in a format like "ls -l"
  • tar xvf /dev/rmt /bin
   extract the /bin directory
  • tar cvf - `find . -print' > backup.tar
   create an archive of the current directory and store it in a file, backup.tar
   (the "-" tells tar to store the directory on standard output, which is then redirected)
  • tar -cvzf libjpeg.tar.gz libjpeg*
   puts files ./libjpeg* into compressed tar named libjpeg.tar.gz
  • tar -cvzf wwwback.tar.gz /var/www puts contents of directory /var/www (including all subdirectories) into the compressed tar named wwwback.tar.gz

backup

mt other tape functionality

cd burning

  • xcdroast does mastering
     N.B. make sure kscd not running!
  • cdlabel makes stick-on labels

/home/oacheson/makecdlabel - script for cdlabel -- generates .ps file.

     Then use ghostview to open and print.

compiling

./configure >& configure.log make >& make.log make install >&make.install.log make clean


disk utilities

  • df size and utilization of partitions
  • du -Sh | sort -n | less
  outputs subdirectories and sizes, by size
What 's eating my disk space?
Tuesday March 30, 2004 (09:00 AM GMT)
By: Wellu Mäkinen
In the past I frequently found myself wondering where all my disk space had disappeared to. Simply using a few
shell commands helped me out. For example:
# du -x --block-size=1024K | sort -nr | head -15
shows me the 15 biggest directories and files below current directory. See relevant man pages for details of the switches. 
  • fdisk partitions
  • mke2fs formats, adds fs
  • parted partition editor

mc Midnight Commander (console)

  • cd /#ftp:[!][user[:pw]@]host[:port][remote-dir]
    • use ! if behind firewall
   e.g., cd /#ftp:guest@remote-host.com:40/pub
    cd /#ftp:tsx-11.mit.edu/pub/linux/packages
   
  • tkAbout tk front end for df
  • tkmc Midnight Commander (X)S with save


EMACS

  • C-h help system
  • C-x C-s save file
  • C-x s save all buffers
  • C-x C-c exit EMACS with save
  • C-x u undo last edit
  • C-g get out of current command
  • C-x 1 1 window
  • C-x 2 split window (same file in both)
  • C-s search
  • C-d delete current character
  • DEL delete previous character
  • backspace delete previous character
  • C-k kill current line (consecutive kills append as single)
  • C-u n C-k kill n lines
  • C-y yank (paste) last text in kill buffer
  • M-y yank with an earlier batch of text
  • C-space set mark. Note: REGION is defined as rectangle from MARK to POINTER
  • M-@ mark word
  • M-h mark paragraph
  • C-w kill region
  • C-x C-l Change case
  • C-x C-u (ditto)
  • C-x TAB indent region
  • C-x print-region print region
  • M-x append-to-buffer appends region to specified buffer
  • M-x prepend-to-buffer prepends
  • M-x copy-to-buffer copy region, deleting buffer's old contents
  • M-x insert-buffer insert specified buffer into current buffer
  • M-x append-to-file append region to specified file
  • C-p up by line or character
  • C-n down by line or character
  • C-f forward by line or character
  • C-b back by line or character
  • C-v Forward by one screen
  • M-v Back by one screen
  • M-x enter command
    • set-background-color )
    • set-foreground-color ) respond with "space" to get color list
    • set-cursor-color
    • list-colors-display lists and shows colors
    • set-face-foreground
    • set-face-background
    • set-face-font
  • Font selection -can do on command line: emacs -fn "longfontname" or by ~.Xdefaults: emacs*font: *-lucidatypewriter-medium-r-normal-sans-14-*-*-*-*-*-*-* kmenu


  • File Handling
    • C-x C-f Find file and read it
    • C-x C-v Find alternate file. Replaces one read with C-x C-f
    • C-x i Insert file at cursor position.
    • C-x C-s Save buffer
    • C-x C-w Save-as. Write buffer contents to file (asks file name)
    • C-x C-c Exit EMACS with save.
    • C-z Suspend EMACS (use exit or fg to restart)
  • GNUS mailreader in emacs
    • ^x-1 1 window
    • O-h save message to MH dir.

grep / find

  • find / -name pattern
   searches for pattern starting in root and descending entire directory tree
  • find . -type d -print # shows every directory from pwd down
  • find ./dir -type d -print # shows every directory from ./dir down
  • find . -maxdepth 1 -type d | cut -c3- | grep -v '^\.' # just names and none starting with dot
  • find /etc -exec grep ishmail {} \; | less
   looks for "ishmail" in all files and/or directories in or under /etc
   use "grepunder startdir pattern" to do this
   
  • find / -perm +4000
   finds all files with suid set
   
  • grep [-e] pattern files
  • ps aux | grep -e nfs
  finds processes with "nfs"

irc

  • /HELP <topic> e.g., newuser, etiquette
  • /JOIN <channel>
  • /LEAVE <channel>
  • /LIST channels [-min <min>] [-max <max>] [<pattern>]
  • /MSG private message <nick> <msg>
  • /NAMES users on channels
  • /NICK change nickname
  • /QUIT
  • /WHO <channel> who's on <channel>
  • /WHOIS <nick>

Lost Password (root)

  • put RedHat cd in cd drive.
  • reboot computer
  • hold down shift key during bios boot (tells system to boot from cd)
  • enter linux rescue mode (single user mode, with very limited file system).
  • mount -t ext2 /dev/hdb3 /foo (mounts hard drive at /foo)
  • chroot /foo (sets new root for file system to hard drive)
  • at this point passwd should allow changing root password. Note: may have to either remove "x" as 2nd entry in /etc/passwd for root, or remove whole root line in same file.
  • reboot. Will take a while, since forced runs.

mail

  • fetchmail --verbose --fetchmailrc /etc/.fetchmailrc --daemon 180
  • pop inbound
  • smtp outbound
  • filtering - ~/.maildelivery contains rules for slocal. 12/15/01 switched to procmail. See below.
  • mutt  ; + mutt command operates on tagged messages in viewer.
  • | urlview runs embedded url's in netscape.
     use ^b as shortcut.
  • i - in COMPOSE, invokes ispell
  • L - reply command for mailing lists
  • T~m 1-1000 tags messages 1-1000 in current directory.

procmail

  ~/.procmailrc controls filtering
  • ^ - start line
  • $ - end line
  • . - any character
  • a* - 0 or more a's
  • a+ - 1 or more a's
  • a? - 0 or 1 a's

mount / umount

  • cdrom mount /dev/scd0 /mnt/cdrom
  • Zip drive insmod ppa
    • mount /dev/sda4 /mnt/zip <== NOTE: do as user oacheson to set permissions right.
    • umount /mnt/zip
    • rmmod ppa
  • floppy (dos) mount -t vfat /dev/fd0 /mnt/floppy

mysql

  • /etc/init.d/mysql (start | stop | restart ...)
  • mysqladmin [OPTIONS] command command
   status - brief server status
  • mysqlbug create bug report and mail. NOTE: uses emacs
  • mysqldump [OPTIONS] database [tables]
   dumping definition and data from db or table
  • mysqlshow lists dbs
  • mysqlshow <db> lists tables in db
  • Paths
    • /usr/local/bin
    • DATADIR=/usr/local/var

News - slrn

  • config: ~/.slrnrc - upgraded 4/3/02 using slrn-provided script.
  • Navigation SPC - message down
    • b - message up
    • n - next message
    • p - previous message
    • h - message view to list view
  • Print
    • y - to lpr
    • | a2ps - to a2ps
  • Mark all read c - in list view
  • Save o - saves article, tagged articles or thread.
  • Scoring
    • K - score a message
    • ESC 1 K - edit scorefile
    • v - show scorefile rules relating to current message

Networking

  • /etc/hosts mini-dns
  • /etc/resolv.conf where dns addresses go
  • /etc/sysconfig/network gateway address, hostname
  • /etc/sysconfig/network-scriptsifcfg-eth0 ip address of eth0
  • /etc/rc.d/init.d/network restart reloads network info
  • lsof - lists open files, where files include devices.
  • ifconfig displays eth configuration

nfs

  • /etc/exports defines who gets access to what
  • /etc/hosts.allow
  • /etc/hosts.deny

example (on sweetums)

  • mount blackhole:/ /mnt/blackhole (mounts root and everything below).
  • mount blackhole:/mnt/cdrom /mnt/cdrom (Note: needed because a diff. file system)

Password restore

see "Lost Password," above.

perl

  • add module via CPAN:
    • perl -MCPAN -e shell
    • install (modulename)

Printing

5/2/04:

  • pr filename prints file through CUPS to HR895
  • a2ps filename does nice 2-page-per-page output.
  • card programname produces compressed command summary from programname help.
  • col - filter reverse line feeds from input
  • /dev/lp0 where my printer is (was /dev/lp1 pre 2.2.9 kernel)
  • /etc/printcap defines printers
  • lpd spooling daemon
  • lpr user spooling command, e.g., pr INSTALL | lpr
  • lpq lists queue
  • lpc control
    • down | up queuing
    • enable | disable printing
    • abort kills daemon
  • lprm removes jobs from print spool
  • turboprint
    • xtpsetup - install new printer
    • xtpconfig - configure printer

Note: /usr/lib/rhs/rhs-printfilters/ contains plugins for magic filter.

  • Default printer: lp
  • export PRINTER=bj (or whatever)
  • PRINTTOOL can do printer setup.
  • also, /usr/bin/redhat-config-printer-gui is good configurator (run as root)
  • mpage multiple pages per sheet of paper
  mpage -2 -P filename    = prints 2 pages of filename per sheet of paper
  • mpage -2 -m40l -r -jfirst[-last][%interval] -P filename
  2 pages per sheet, reverse order, from first to last skipping interval outputting to LPR
  • pscal mm yyyy > file generates a postscript calendar for the specified month.
  • pstools
    • epsffit fit encapsulated PostScript file (EPSF) into constrained size
    • extractres filter to extract resources from a PostScript document
    • fixdlsrps filter to fix DviLaser/PS documents to work with PSUtils
    • fixfmps filter to fix Framemaker documents so PSUtils work
    • fixmacps filter to fix Macintosh documents with saner version of md
    • fixpsditps filter to fix Transcript psdit documents so PSUtils work
    • fixpspps filter to fix PSPrint PostScript so PSUtils work
    • fixscribeps filter to fix Scribe documents so PSUtils work
    • fixtpps filter to fix Tpscript documents to work with PSUtils
    • fixwfwps filter to fix Word for Windows documents so PSUtils work
    • fixwpps filter to fix WP documents so PSUtils work
    • fixwwps filter to fix Windows Write documents so PSUtils work
    • psbook rearrange pages in PostScript file into signatures
    • psmerge filter to merge several PostScript files into one
    • psnup multiple pages per sheet
    • psresize multiple pages per sheet
    • psselect select pages from a PostScript file
    • pstops shuffle pages in a PostScript file

samba

  • smbstatus
  • http://blackhole:901/ runs SWAT. Login as root or oacheson. pw is current system pw (not samba pw).
  • LinNeighborhood gui samba client

scanning

  • xscanimage part of sane
  • gimp - acquire command

Security

  • /usr/src/john-1.6/run/john passwdfile
  john the ripper password cracking
  • nessus heavy duty port scanner
  • nmap heavy duty port scanner - highly recomended.
  See linuxJournal - 5/01 article
  • ssh configured as v.2 default. Handles v.1, as well.

System administration tools

  • chattr can make files read-only (and other attributes).
  • crontab filename sets up cron commands in "filename" in /var/spool/crontab
  • env displays environment
  • groupadd adds new groups
  • last - log of recently logged on users
  • ldconfig -v updates libraries
  • logger "message" put "message" into log
  • netdate get timedate from netserver; set local
  • ntpdate ditto
  • nslookup query internet name servers interactively
  • dig
  • host
  • passwd changes passwords
  • uname -a gets builddate and version of kernel
  • uptime time since last boot
  • useradd adds new user (default files and directories from /etc/skel)
  • usermod modifies existing user, e.g.
     useradd -g primary_group -G adtl_grp_1,adtl_grp_2,... -s /bin/shell -p xxxx -d /home/roger -m roger
  • userdel delete a user
  • w currently logged on users
  • who ditto
  • xwhois queries internic, et al.
  • shadow stuff use these instead of the linux standards
    • useradd
    • usermod
    • userdel
    • useradd defaults are stored in /etc/default/useradd
    • passwd (yes, it's still the same command)
  see "Lost Password," above, for recovery from lost root password.

watch

Use watch 'process' to repeatedly run a process to see changes over time.

Web page

X Windows Stuff

  • xev - gives keycodes for any key pressed.
  • xmodmap - utility for modifying keymaps and pointer button mappings in X

kde

  • /usr/local/kde/bin/startkde starts kde
  • startx starts X. Controlled by .xinitrc
  • XScreenSaver (see man xscreensaver)
 xscreensaver -timeout 1 -cycle 1 &
   "disabling server builtin screensaver. Re-enable it with "xset s on"
  • xdpyinfo lots xwindows infor. also man page

xterm

  • xterm -fn 10x20 starts xterm in "huge" font

Bottom of Page