LINUX NOTES -- Richard Sonnenfeld -- Version 2.2 May 31, 2005 THIS IS LINUXNOTES5 LINUXNOTES5.RS Primary copy resides on feynman (heisenberg@feynman.nmt.edu) LINUXNOTES5P.RS Is always Linuxnotes 5 but with "DELETEME" sections removed Secondary copy on Ramanujan xxxxxGCC TOOLCHAIN ================================================= This subsection on the GCC Toolchain may well grow into its own separate file, so I am using the &&&& character to distinguish these lines. xxxxx&&&&MAKE ================================================= &&&&MAKE and the KERNEL root@dirac src # make menuconfig make: *** No rule to make target `menuconfig'. Stop. This incredibly unhelpful message simply means you aren't in the same directory as your .config file. Go there and it will work. make menuconfig creates a .config file which other programs can use, even if you change no options. The .config file is primarily (solely?) used for recompiling the kernel. Here is where to find .config root@feynman src # pwd /usr/src root@feynman src # ls linux linux-2.4.26 linux-2.6.10-gentoo-r6 pc pebble.v41 redhat (There is a .config under EACH of these linux flavor subdirectories intended for compiling that particular flavor of linux.). The .config file is so important, particularly for gentoo, that I practice "config hygiene" as follows: root@feynman boot # pwd; ls /boot boot kernel_2.6.10-gentoo-r6_V2.config grub kernel_2.6.10-gentoo-r6_V3 kernel_2.6.10-gentoo-r6 kernel_2.6.10-gentoo-r6_V3.config Note that each compiled kernel also has a text file stored with it. When recompiling the dscud driver for Prometheus, for example, the contents of .config are used even though the kernel itself is not recompiled. &&&&MAKE and GCC When you use a makefile to compile any C program, where environment variables aren't specified, they are read from /etc/make.conf. Here is an excerpt from make.conf: # Host and optimization settings # ============================== # # For optimal performance, enable a CFLAGS setting appropriate for your CPU. # # Please note that if you experience strange issues with a package, it may be # due to gcc's optimizations interacting in a strange way. Please test the # package (and in some cases the libraries it uses) at default optimizations # before reporting errors to developers. # # -mcpu= means optimize code for the particular type of CPU without # breaking compatibility with other CPUs. # # -march= means to take full advantage of the ABI and instructions # for the particular CPU; this will break compatibility with older CPUs (for # example, -march=athlon-xp code will not run on a regular Athlon, and # -march=i686 code will not run on a Pentium Classic. #CFLAGS="-mcpu=athlon-xp -O3 -pipe" CFLAGS="-march=pentium3 -O3 -pipe" We did INDEED experience "strange errors" (segmentation faults, "illegal instruction") when running balloon_tx on prometheus after compiling it on a machine with CFLAGS -march attribute set. It's makes sense. We were compiling on a pentium3, but the prometheus is a 486. This sort of thing can be overcome by directly specifying the "march" attribute in the makefile of the relevant program. Remember GCC can compile for just about ANY linux-supported architecture. So cross-compiling is really not a problem, so long as you specify WHAT you are compiling for. &&&&STRACE The tool "strace" for system trace is great for debugging. Let's say your favorite program "timmy" crashes with a segment fault or something worse. Run timmy as "strace timmy". Timmy begins, but you see all the system calls and can tell where it may have broken. xxxxxINSTALLED APPS ================================================= In Approximate order: xxxxxRC-UPDATE =============GENTOO SPECIFIC====================================== Nice script for adding new services to startup. Must be run as root. rc-update -s (Shows all services, only those which show a run-level (e.g. boot, default) next to them are running. Others are available to be added. So to add ntpd to the default level rc-update add ntpd default xxxxxJPILOT====================================== Run as jpilot Stores data in .jpilot Stores config in .jpilot/jpilotrc (When do "preferences" from the application the data goes there). Here's my discussion on adding it. http://forums.gentoo.org/viewtopic-p-2229684.html#2229684 xxxxx.RC FILES====================================== /etc/profile (Only accessible by root) -- Lasts through all sessions /home/heisenberg/.bashrc -- Only lasts through current shell /home/heisenberg/.pinerc (for mail program) ... /home/heisenberg/.mailrc (other general settings ... I think apply to pine too?) /etc/profile (not an rc file, but sets up environment at boot) /etc/inittab (Tells "init" what to do ... one of the very first things Linux looks at.) .procmailrc (Where to put the spam filters ... here's a sample) :0: * !^(To|Cc):.*joeuser@.*nmt.edu * !^(To|Cc):.*joeuser@nmt.edu * !? formail -x"From:" -x"From" -x"Sender:" | egrep -is -f $HOME/.mail_whitelist $HOME/mail/IN.spam :0: * ? formail -x"From:" -x"From" -x"Sender:" | egrep -is -f $HOME/.mail_blacklist $HOME/mail/IN.spam xxxxx.BASHRC====================================== The .bashrc file is visible with ls -a and is in your home directory. If you are root, it is in /root # set a fancy prompt PS1='\u@\h:\w\$ ' PS1='#user@host\pwd\$ ' Full path name. #Colorize ls and sort files in time order alias ls="ls --color=auto -t" More about Fancy Bash prompts: ======This is a script called fancy.scr #!/bin/bash #To use this: # source fancy.scr # fancy function fancy { local GREY="\[\033[1;30m\]" local RED="\[\033[1;31m\]" local GREEN="\[\033[1;32m\]" local YELLOW="\[\033[1;33m\]" local LIGHT_BLUE="\[\033[1;34m\]" local PINK="\[\033[1;35m\]" local TURQUOISE="\[\033[1;36m\]" local WHITE="\[\033[1;37m\]" local NO_COLOUR="\[\033[0m\]" #PS1="$YELLOW\u@$LIGHT_BLUE\h$PINK:$TURQUOISE\w\$ " PS1="$YELLOW\u$RED@$WHITE\h$RED:$TURQUOISE\w\$ " } Bash 2.02 Man Page When executing interactively, bash displays the primary prompt PS1 when it is ready to read a command, and the secondary prompt PS2 when it needs more input to complete a command. Bash allows these prompt strings to be customized by inserting a number of backslash-escaped special characters that are decoded as follows: \a an ASCII bell character (07) \d the date in ``Weekday Month Date'' format (e.g., ``Tue May 26'') \e an ASCII escape character (033) \h the host name up to the first ``.'' \H the host name \n new line \r carriage return \s the name of the shell, the base name of $0 (the portion following the final slash) \t the current time in 24-hour HH:MM:SS format \T the current time in 12-hour HH:MM:SS format \@ the current time in 12-hour AM/PM format \u the user name of the current user \v the version of Bash (e.g., 2.00) \V the release of Bash, version + patch level (e.g., 2.00.0) \w the current working directory \W the base name of the current working directory \! the history number of this command \# the command number of this command \$ if the effective UID is 0, a #; otherwise, a $ \nnn the character corresponding to the octal number nnn \\ a backslash \[ begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt \] end a sequence of non-printing characters $LOOPING IN BASH -- LOOPING FOREVER #!/bin/bash until [1 = 0] #until [ "$var1" = end ] #Note -- need a space between left bracket and anything else. do ps -A |grep firefox echo "Input var1"; read var1 done exit 0 xxxxxADDUSER and USERADD ========================================= On Red Hat, the scripts are not in path, but they still exist. /usr/sbin/useradd ralph -pjoe Adds new user ralph with password joe xxxxxAPT-GET =======DEBIAN SPECIFIC================================= apt-get install lynx OR apt-get whateverpackage dselect . if interrupted by Ctrl-C , do access (step 1) and then go back to install xxxxxBASH ====================================== In addition to running scripts, you can create functions which you call by name. The following file, called new.scr demonstrates this. The trick is the command "source" #!/bin/bash #To use this: #heisenberg@dirac heisenberg $ source new.scr #heisenberg@dirac heisenberg $ new heisenberg linux OUTPUT: #heisenberg Has added a new function to linux function new { echo $1 "Has added a new function to" $2 } xxxxxBASH ENVIRONMENT VARIABLES====================================== Linux Environment variables (bash) echo $TERM or echo $COLORTERM (gives values of these variables) TERM (no $) TERM=xterm or TERM=xterm-color sets the variables. gnome-terminal --background yellow foreground --black printenv - Shows all environment variables currently defined. In bash # is the comment character. To execute a shell script. Type bash script_name, even if it isn't executable. bash Richard.bat Long directory names. Use "" . Thus cd "Selected earlier vers for reference". xxxxxBOOT PROCESS==================================== http://www.faqs.org/docs/kernel_2_4/lki-1.html#ss1.2 http://www.bglug.ca/articles/linux_boot_process.html http://www.pjrc.com/tech/8051/ide/fat32.html Is there any method to reinitialize init process without rebooting the system? I mean the init process should be killed and reinitialized to previous state. /sbin/telinit -q will send the init process the correct signals to have it reread inittab. Note: playing around with init is not for the faint of heart. You should really know what you are doing or its possible to disable part or all of your system. There is also in the man page of init description of how to test init by running it in user space using an alternate directory as the root as far as the test is concerned. Here is an excerpt from its man page: TELINIT /sbin/telinit is linked to /sbin/init. It takes a one- character argument and signals init to perform the appro- priate action. xxxxxCAT ========================================= cat file1.txt divider file2.txt divider >>linuxnotes.rs ConCATenates 4 files to create linuxnotes.rs xxxxxCHMOD CHOWN ============================================================= chmod can be run as any user. chown can only be run as root. chown heisenberg temp.txt changes owner to heisenberg from whoever it was. chgrp heisenberg temp.txt changes group ls -l shows owner AND group xxxxxCHROOT ================================================= Chroot had mystified me. I thought it was literally changing what kernel you were running or something really tricky. In fact, it only redefines the "root" of your filesystem. YOu are most likely to use as follows. "Root" is usually the directory /. However, let's say you are working off of a compact flash but booted from the hard drive. YOu can change your "root" from harddrive to flash by chroot /mnt/flash Then cd /etc actually puts you in /mnt/flash/etc rather than /etc. (However a pwd will only return /etc ... which bothers me.) Why is this necessary? Let's say want to run lilo to make a compact flash bootable by running lilo. Could do /mnt/flash/sbin/lilo. However, lilo by default looks for /etc/lilo.conf. Thus, even though you were running lilo on the flash, it would still pull the lilo.conf from the hard-drive. Doing a chroot /mnt/flash /sbin/lilo runs the lilo on the flash and pulls lilo.conf from /etc on the flash. xxxxxCONSOLE AND TERMINAL SWITCHING =========================== In Debian command line, it's Alt-Fn (n=1-6) to get different screens. However, once launch Xwindows, it's Ctrl-Alt-F1 to launch a separate terminal screen, and Ctrl+Alt+F7 to get back to the GUI. To Reset a terminal that is printing gobbledgook instead of proper letters. Type RESET. To clear a terminal "CLEAR" xxxxxCOREUTILS ================================================= info coreutils ... shows most of the core unix commands, and shows them well. In fact, note suggest that the MAN pages are no longer maintained and coreutils is a better description. To use info, use letter P, N and U to navigate. xxxxxCRON JOBS========================================= Setup a cron job crontab -uheisenberg -l (to list) and crontab -uheisenberg -e (to edit) If crontab doesn't allow you to do this, put the name heisenberg in the file. /etc/cron.allow (create the file if you need to). You do not need to stop and start cron ... at least not when using crontab, possibly when creating the cron.allow file. Here is a working crontab file # Beginning of crontab file SHELL=/bin/bash # Select a shell to use * * * * * /bin/echo "One minute has elapsed">>/home/heisenberg/rscron.log # Output this message every minute. Note that have to use a path # explicitly for echo as the usual path is not what cron uses. Without the # /bin, this script produces no output. 0 "9,14" * * * /bin/echo "It must be either 9 am or 2 pm">>/home/heisenberg/rscron.log Using crontab and sendmail to routinely mail a message: crontab: 30 14 * * 5 /bin/mail -s "it's Friday" user1@xx user2@xx < /mydir/mymessage.txt Works great! -s for subject line < for file to be attached. xxxxxCOPYING FILES w WILDCARDS========================================= Example pwd "/home/heisenberg/" mkdir installs cd installs cp ../n* . (copies all files starting with n from /home/heisenberg to /home/heisenberg/ installs) cd .. rm * (deletes all files in /home/heisenberg, but doesn't delete the subdirectories) xxxxxCRONTAB =========================================================== Editing crontab ... crontab -uheisenberg (have already put heisenberg in the "allow" file) crontab -uheisenberg -l or crontab -uheisenberg -e Look in /var/log/cron.log as well Crontab examples Note: commands executed by crond have no associated terminal ie. standard output & standard error must be redirected. 0 * * * * echo Cuckoo Cuckoo 2>&1 /dev/console Every hour (when minutes=0) display Cuckoo Cuckoo on the system console. 30 9-17 * 1 sun,wed,sat echo `date` >> /date.file 2>&1 At half past the hour, between 9 and 5, for every day of January which is a Sunday, Wednesday or Saturday, append the date to the file date.file 0 */2 * * * date Every two hours at the top of the hour run the date command 0 23-7/2,8 * * * date Every two hours from 11p.m. to 7a.m., and at 8a.m. 0 11 4 * mon-wed date At 11:00 a.m. on the 4th and on every mon, tue, wed 0 4 1 jan * date 4:00 a.m. on january 1st 0 4 1 jan * date >>/var/log/messages 2>&1 Once an hour, all output appended to log file ps -Af is all processes with detail ps a or ps au or ps aux (seems to like without the -) in debian. or ps aux |grep cron Look at the scripts in /init.d ... they all tell you how to kill their processes and restart them. garage:/etc/init.d# /etc/init.d/cron restart Restarting periodic command scheduler: cron. xxxxxDATE / TZCONFIG ================================================================ tzconfig to set time zone on a computer. xxxxxDATE / TIME ================================================================ To set Hardware clock of PC to Linux system time, you don't need to mess w/ BIOS. As root, type hwclock --systohc. This is often done before shutdown to make next reboot more accurate. heisenberg@garage:~$ date +%s 1073612223 heisenberg@garage:~$ date +%s 1073612234 %s Argument for expressing current time in seconds from 1970. heisenberg@garage:~$ date +'%h %H %M %S %N %s' Jan 19 04 03 449470000 1073613843 Note that putting spaces between the arguments makes results have spaces as well. Single quotes are needed though. %h actually means "month", but %H means hour as you'd expect. %N is nanoseconds! Setting time in Linux. First, need to be a su. Then date -s11:06:45 will set the time to 11:06:45 and leave time zone and date unchanged. Default is to use UTC time on machine. Add 6 or 7 hours to Socorro time for UTC. (Depends on Daylight savings) date -s'19:59:30' also works. Here's how to set more than just the time. liles:/# date -s'Sun Apr 24 20:13' Sun Apr 24 20:13:00 MDT 2005 During summer, 12:00 in NM Socorro is 18:00 UTC. In winter it is 19:00 UTC. xxxxxDIFF /$SDIFF ========================================= diff --side-by-side filea fileb (Nice side by side format) sdiff -ooutputfile file1 file2 (Interactive merge of different files) Type "l" or "r" to use output from left or right file. Example: sdiff -ofstab_new ._cfg0000_fstab fstab Bad_Example: sdiff -ofstab ._cfg0000_fstab fstab It may seem more efficient to do this sort of interactive merge right to one of the files ... but it seems it may erase the whole file if not careful. So better to merge to a new file and then copy that over the old file when done. xxxxxDIRECTORY STRUCTURE ======================================================= /usr/bin seems to be where executables (apps) are stored /usr/X11R6/bin Many of the GUI apps are kept here /etc/ seems to be for system stuff (like passwords) /var/log for system logs /bin -- Typical linux commands /boot -- The boot block (boot.b), The kernel (vmlinuz ...) /etc -- Lots of configuration files, host.conf, lilo.conf, crontab, passwd /etc/init.d -- Lots of boot scripts, startup scripts /etc/apt/sources.list (shows all possible files you can get w/apt-get) DEBIAN SPECIFIC /etc/X11 -- XFree86config (setting up X-windows) /sbin lots of scripts e.g. ifup, ifconfig, insmod, hdparm, modprobe /proc -- Some processes and interesting files, /proc/version shows linux version. To find out what version you are running, also can type dmesg and look at start-up messages xxxxxDPKG=======DEBIAN SPECIFIC================================= Just as red-hat has RPM's, Debian has .deb files After downloading a .deb file To install the .deb package, the following command should suffice: dpkg -i pine_4.61_i386.deb Uninstalling the package can be done by running the command dpkg -r pine xxxxxDISTROS WINDOW MANAGERS ========================================= Mini Linuxes -- Small Distros for weak machines (486 32 MBytes memory). DSL (Damn Small Linux - A Debian variant) FeatherLinux -- A Knoppix remaster with more features than DSL. All include Windowmanager (Light ones like Fluxbox and Icewm) and Browsers xxxxxDISPLAY MODE SWITCHING ========================================= If have multiple modes (resolutions) in Xwindows, toggle with Ctrl-Alt-+ xxxxxINSTALLING A NEW PARTITION FROM SCRATCH ========================================= Let's say that you have a running Linux system, but you have unused disk space and you want to install a new partition to take advantage of it. In a nutshell: FDISK to create the new partition mke2fs to "format" it for ext2 or ext3 mount or edit /etc/fstab That's it. Here are details: xxxxxFDISK -m (menu) -p (list partitions) -n (new partition) Command action e extended p primary partition (1-4) Choose p (Unless you are trying to have more than 4 total, in which case you need to choose e first) Enter first cyl (it suggests a default). Enter Final Cyl (or can enter +10000m, which means 10 Gbytes). After that use -t to set type. There are many supported types. You want to select type "c" which is vfat (LBA MODE). vfat is FAT32. Continue in this way to create the other partitions. All partitions are of type "primary". Only create an extended partition if can't do the job with four primary partitions. Each HDD can only have up to four primary partitions on it. When creating the Linux partitions, select file type Linux swap for the swap system, and file-type Linux for Ext3. Here's an example (on a scsi disk) Device Boot Start End Blocks Id System /dev/sda1 1 3258 26169853+ 83 Linux /dev/sda2 3259 6516 26169885 83 Linux /dev/sda3 6517 9774 26169885 83 Linux /dev/sda4 9775 22800 104631345 5 Extended /dev/sda5 9775 13032 26169853+ 83 Linux /dev/sda6 13033 16290 26169853+ 83 Linux /dev/sda7 16291 19584 26459023+ 83 Linux Here's another example Partition Mount point Size /dev/hda1 /boot (15 megs) /dev/hda2 windows 98 partition (2 gigs) /dev/hda3 extended (N/A) /dev/hda5 swap space (64 megs) /dev/hda6 /tmp (50 megs) /dev/hda7 / (150 megs) /dev/hda8 /usr (1.5 gigs) /dev/hda9 /home (rest of drive) After you've made linux partitions, you need to put file-systems on BEFORE you mount them. (Otherwise get error from mount command) Use /sbin/mke2fs /dev/hda5 or /sbin/mke2fs -j /dev/hda5 for journaling (ext3) [Of course, before you mount, you need to create the mountpoint. You can do this with the ordinary mkdir command] Then mount -t ext3 /dev/hda5 /mnt/newhome mount -r -t ext3 /dev/hda5 /mnt/gentoo ... Mounts drive readonly. Look under /dev to see what device names are. Finally mount -l #Just to check whether you did it right! /dev/hda3 on / type ext2 (rw,errors=remount-ro) [] proc on /proc type proc (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) /dev/hda5 on /mnt/newhome type ext3 (rw) [] And then df -h Filesystem Size Used Avail Use% Mounted on /dev/hda3 989M 510M 429M 55% / /dev/hda5 21G 33M 20G 1% /mnt/newhome Now let's say you want this to happen automatically, you need to edit /etc/fstab. It turns out the "options" portion of fstab matters, as does the pass column. Here is a working fstab: # /etc/fstab: static file system information. # # /dev/hda3 / ext2 errors=remount-ro 0 1 /dev/hda5 /mnt/newhome ext3 defaults 0 2 /dev/hda1 none swap sw 0 0 proc /proc proc defaults 0 0 #/dev/fd0 /floppy auto user,noauto 0 0 /dev/cdrom /cdrom iso9660 ro,user,noauto 0 0 Before I changed pass to 2 and options to defaults, I couldn't get /dev/hda5 to mount. For more generality, you can use a "label" instead of a device name. If you had a /dev/hda6, I think duplicating the /dev/hda5 line would work. The pass would stay at "2" (not 3). xxxxxEMERGE=============GENTOO SPECIFIC========================== emerge -pv gnome-cups-manager (if that's not OK quit. If looks good then remove the -p for pretend and actually do it.) If emerge shows "blocking" read the manual. It means your new app will clobber something else. xxxxxERROR MESSAGES ========================================= Note that result: ENOTTY which is kernel speak for "Error, this file handle doesn't refer to a terminal device (TTY)" xxxxxFILE TYPES FOR SCIENTIFIC DATA ANALYSIS ========================================= .png, .bmp, .gif, .jpg are all fine so long as they are created at a size that is close to what you will use. If you use .ps and .eps, EVERY data point is included, even if it overlaps a neighbor at the visual scale. Because of this, you can blow an EPS up VERY LARGE and it uses ALL available paper space. .ps is good for direct printing. .eps is for embedding in a document. xxxxxFSTAB ========================================= # dirac.nmt.edu:/etc/fstab: static file system information. # /dev/md0 / ext3 noatime 0 0 #Is traditional to have a /boot partition for kernel, but we'll keep our directory in /boot off of the / partition. #noauto means don't mount at boot /dev/md1 none swap sw 0 0 /dev/md7 /home ext3 noatime 0 0 /dev/cdrom /mnt/cdrom iso9660 noauto,ro,exec 0 0 #/dev/hdc /mnt/cdrom iso9660 noauto,ro,exec 0 0 #The exec option allows to run programs off CD-ROM /dev/fd0 /mnt/floppy auto noauto 0 0 #Auto detects the type -- Can put explicitly -t msdos, but not needed. # NOTE: The next line is critical for boot! none /proc proc defaults 0 0 # glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for # POSIX shared memory (shm_open, shm_unlink). # (tmpfs is a dynamically expandable/shrinkable ramdisk, and will # use almost no memory if not populated with files) # Adding the following line to /etc/fstab should take care of this: none /dev/shm tmpfs defaults 0 0 # USB FLASH # /dev/sdc1 /mnt/flash auto user,rw,noexec,noauto 0 0 # USB PROMETHEUS FLASH /dev/sdc1 /mnt/cf1 auto defaults 0 0 #The above line is significant. defaults allows chroot and lilo to run on /dev/sdc1. #Note that sdc2 has "noexec". This means that, despite everyting else being good, you #can't execute any commands on that partition. /dev/sdc2 /mnt/cf2 auto user,rw,noexec,noauto 0 0 # This line (added by R.Sonnenfeld) enables additional logging of usb events. none /proc/bus/usb usbdevfs defaults 0 0 xxxxxFTP ========================================= Seemed unable to get ftpd running on gentoo. Read the ftpd man page. You need to set up a directory called ftp (and maybe anonymous as well). It explains permissions and symbolic links. inetd needs to be running before start ftpd. (xinetd on gentoo). These also have man pages. xinetd works off of xinetd.conf and xinetd.d (xinetd.conf has a line saying "includedir" which points you at xinetd.d ...whew!) i.e. includedir /etc/xinetd.d Spent a lot of time on man pages for ftpd and xinetd. Ending up creating some of the suggested files (most of which are in etc). Found a directory called xinetd.d which contains files to configure each of a variety of services (as ftp, time-tcp etc.) I modified the ftp entry to disable = no. That might help. Before I did that, starting xinetd and it went back to sleep. After I did that xinetd continued to exist, but ftpd still did not seem to start. So that's part of it! xxxxxGENTOO LINUX==================================== There is some debate about whether compiling from sources yields a faster system than installing binaries. There is general agreement that GENTOO Docs are very good and educational about Linux in general. A "Stage 3" Gentoo installation is a precompiled installation. It is fastest. Stage1 and Stage2 you compile either completely or mostly from scratch. The Stages refer to the names of tarballs that have the source code. Debian and Gentoo get comparable comments on ultimate speed and even on performance on new hardware. (So long as "Sarge" distro of Debian is used and not Woody.) There is frustration w/ how slow a Gentoo install is compared to Debian. xxxxxGENTOO IDIOSYNCRACY 1) Gentoo prevents you from SU's to root unless you are a member of a group called "wheel". This is annoying. When create a new user, Gentoo provides the superadduser script, this automatically puts you in the group users and then allows you to add another group (e.g. wheel). 2) Can't ssh into a gentoo machine unless sshd is started. 3) To automatically start things at boot, run for example "rc-update add sshd" All startup scripts for gentoo are in /etc/init.d 4) To add user heisenberg to "wheel" group (after have already created ID without it, edit the /etc/group file. Replace the line wheel::10:root with wheel::10:root,heisenberg Works instantly. NO reboot. xxxxxGENERAL TROUBLESHOOTING==================================== Symptom: Command goes off into space If a network command, like ping goes off into space and appears to just hang (no response, blank screen after send the ping, then you have a flaky network connection. Check that eth0 is running (for example, /sbin/ifdown eth0 and then /sbin/ifup eth0). If it is, then it is your physical connection (cable is broken, port is dead). I have seen this occassionally with my desktop machine and it can be fixed by moving cable into my hub and then ... back into original state .... scary. I've replaced more than one cable over this ... I don't think it really is the cable! Another symptom of this is if lpq fails (by hanging). It's trying to query a network printer, but because of network problems it can't. So if lpq hangs, see if it's because all network services are messed up rather than futzing w/ the printing. xxxxxGNOME========================================= To add an icon to Gnome toolbar - e.g. Netscape. Could just open up terminal window and go Netscape &, however, can also open up "home" window in Gnome Explorer and type / and then go down thru directories to find the executable you want. Can then drag onto toolbar, can also select an icon for it. To switch desktops (GNOME, KDE etc.) use "switchdesk" from the command line. MOUNTING A REMOTE COMPUTER AS A FOLDER IN GNOME FILEMANAGER Applications / File-Browser / File / Connect-to-Server/ Then fill out the following fields: Service Type SSH Server 10.0.100.179 or rainbow.nmt.edu etc. Port (blank) Folder (blank) User name rsonnenf Name to use -- Whatever It creates the icon ... then when you click it. It asks you to log in. Select "save password and save on keyring". Sometimes it doesn't seem to let you login. It seems that it has to create two icons. You can get into the second one. God knows why. CUT AND PASTE BETWEEN WINDOWS IN GNOME ========================================= Can have multiple terminal windows open. Just select text in one window with mouse, then just paste it into other window. Don't need Ctrl-C or Ctrl-V. Is why X-windows stuff has "paste" only, but not "copy". Resizing a rogue Window (e.g. Netscape takes up entire screen). Holding down the "Alt" key allows one to drag a window (in Gnome, at least) regardless of whether can reach title bar. Then can easily resize. xxxxxHARDWARE IDENTIFICATION========================================= How to identify hardware in a running machine . ISA Devices (forget it) PCI Devices . lspci .v PCMCIA/Cardbus . cardctl ident USB Devices . Have to look in dmesg xxxxxIMPORT=(SCREEN CAPTURE)=================================== import - capture some or all of an X server screen and save the image to a file. DESCRIPTION Import reads an image from any visible window on an X server and out- puts it as an image file. You can capture a single window, the entire screen, or any rectangular portion of the screen. Use display for redisplay, printing, editing, formatting, archiving, image processing, etc. of the captured image. The Import Screenshot Method The following assumes a Linux box named servername and a user named username, with which you do your examples for your documentation. From the console, log into your xserver as the same user as you're doing your Samba testing with (username) Make sure you're at the screen resolution and color depth specified by your publisher, or greater. Best images occur when the screen resolution and color depth *exactly* match your publisher's specification. Close all windows, move all buttonbars to the side. From another box, open a telnet into your Samba server, using user username. This can also be done with a virtual terminal. Run the program for which a screenshot must be taken, from the command prompt in the telnet session. The trick is to use the display option, i.e. $ netscape -display servername:0 & Note that unless you have more than 1 keyboard or 1 monitor attached to the server, the display is always boxname:0 On the server X console, do whatever you need to do to get the shot lined up. This includes setting exactly the right window as active, putting the mouse pointer out of the way or pointing to a menu selection, etc. From the telnet session, logged in as username (this will fail otherwise), take your screenshot with this command: $ import -window root -display servername:0 myfile01.pcx Repeat the preceding steps for all your screenshots, using different filenames. xxxxxLILO==================================== * Issue 'dolilo' instead of 'lilo' to have a friendly wrapper that * handles mounting and unmounting /boot for you. It can do more then * that when asked, edit /etc/conf.d/dolilo to harness it's full potential. 5) Update and install lilo on the CF cd /mnt/sdX1/etc cp lilo-standard-hdc.conf lilo.conf (note) for console output to com1 there is a lilo-serial* file you can use instead. vi lilo.conf to look like ####################################################################### NOTE: boot and disk below must be set to wherever your distro # is currently mounted (while you're installing LILO). Don't mess # with anything else unless you really know what you're doing. # boot = /dev/sdX disk = /dev/sdX bios = 0x80 compact delay = 1 serial=0,38400n8 image = /boot/vmlinuz-2.4.26-pebble root = /dev/hda1 append="console=ttyS0,38400n8" label = pebble read-only ##################################################################### Debugging lilo -- I tried to run lilo as below dirac etc # cp lilo.conf.example.prometheus /mnt/cf1/etc/lilo.conf dirac etc # chroot /mnt/cf1 lilo -t (-t means test ... don't do it.) Error was "Permission denied" (or similar). Why? Was lilo executable? (Y) Was chroot? (Y). Was I root? (Y). Did I have correct path? (Y). Problem was that when had mounted cf1, had mounted it with "noexec, nosuid" option. Bad! When fix it, everything works great! Here's what you get when it works properly: dirac etc # chroot /mnt/cf1 lilo -t (-t means test ... don't do it.) Warning: LBA32 addressing assumed Warning: COMPACT may conflict with LBA32 on some systems Setting DELAY to 20 (2 seconds) Added pebble * The boot sector and the map file have *NOT* been altered. NOW DO IT FOR REAL dirac etc # chroot /mnt/cf1 lilo -v LILO version 22.2, Copyright (C) 1992-1998 Werner Almesberger Development beyond version 21 Copyright (C) 1999-2001 John Coffman Released 05-Feb-2002 and compiled at 20:57:26 on Apr 13 2002. MAX_IMAGES = 27 Warning: LBA32 addressing assumed Warning: COMPACT may conflict with LBA32 on some systems Reading boot sector from /dev/sdc Merging with /boot/boot.b Setting DELAY to 20 (2 seconds) Boot image: /boot/vmlinuz-2.4.26-pebble Added pebble * Backup copy of boot sector in /boot/boot.0820 Writing boot sector. xxxxxGRUB==================================== http://www.tldp.org/HOWTO/Multiboot-with-GRUB-2.html http://www.gnu.org/software/grub/manual/ (See LILO) xxxxxHEAD ======================================== head messages -- Lets you print the initial lines of any file. head longdata.txt >excerpt.txt let's you cut off the top of a file easily. (See TAIL) xxxxxHELPFUL WEBSITES========================================= www.tldp.org is all you need in Linux docs. www.linuxquestions.org There is a great description of linux internals (what you can learn from /proc the boot process, good stuff and very readable) http://www.bb-zone.com/SLGFG/toc.html Specifically, it's called "Suse Linux Guide for geeks". So far, I found everything in it applied to gentoo as well. I'm sure there are some differences. (It looks like the init.d tricks in Suse are very close to Debian, but somewhat different than Gentoo) http://www.linuxprinting.org/ Use foomatic if necessary (or ordinary CUPS). Advice from linuxprinting.org ... You can see which cups-raster drivers are installed by examining the filters in /usr/lib/cups/filter; usually cups-raster drivers have names beginning with "rasterto". Each cups-raster driver program will also have one or more PPD files in /usr/share/cups/model, each containing a reference to the proper cups-raster program. Ghostscript Ghostscript is present on most free and many commercial Unix systems. Ghostscript contains many "compiled-in" drivers. You can see the available Ghostscript drivers on your system by running 'gs -h'. If the driver you need is not listed, you need to obtain a new Ghostscript package which includes this driver, or compile Ghostscript yourself. ESP GhostScript includes the largest set of drivers, so is probably the best choice. For some third-party drivers, the driver authors distribute special Ghostscript packages including the needed driver; give that a shot first. xxxxxHOSTS.ALLOW========================================= These files (hosts.allow and hosts.deny) are used by xinetd at least so specify who may use its many services (e.g ftp, ssh, scp). #/etc/hosts.allow # Allow all clients in the 192.168.1.0/24 network and the client at 63.21.45.2 access # to sshd and imapd. sshd, imapd:192.168.1. 63.21.45.2 # For a multi-homed host, you can specify the interface. This allows all hosts # in the 192.168.1.0/24 to access in.ftpd, but only if it's through the 192.168.1.10 interface. in.ftpd@192.168.1.10:192.168.1. # Allow access to pop3d by all hosts in the somedomain.com domain. pop3d:.somedomain.com # Another way to specify network netmasks vsftp:192.168.1.0/255.255.255.0 # Allow access to telnet from the 'research' network (specified in /etc/networks or NIS) in.telnetd:@research #/etc/hosts.deny # Deny access to all services that aren't explicitly permitted in /etc/hosts.allow ALL:ALL xxxxxHOSTNAME========================================= If you need the ip address of a machine and know it's name, a ping of name.nmt.edu will allow name resolution and show you the ip address. What if you need to go backwards? You know IP address but not host name? Use "host". Host 129.138.42.254 "host" seems to be default with Red Hat and Debian. Gentoo does not seem to have it installed by default. Emerge it as "emerge -v host". However, when it installs, it installs the command hostx rather than host. Thus: root@feynman richard # hostx 129.138.42.65 Name: sprite1.nmt.edu Address: 129.138.42.65 xxxxxLILO==================================== http://www.tldp.org/HOWTO/LILO-2.html Most Lilo installations use a configuration file like the following one: boot = /dev/hda # or your root partition delay = 10 # delay, in tenth of a second (so you can interact) vga = 0 # optional. Use "vga=1" to get 80x50 #linear # try "linear" in case of geometry problems. image = /boot/vmlinux # your zImage file root = /dev/hda1 # your root partition label = Linux # or any fancy name read-only # mount root read-only other = /dev/hda4 # your dos partition, if any table = /dev/hda # the current partition table label = dos # or any non-fancy name ================================================================================== When I had a PRI DOS and and EXT DOS partition, I had problems (perhaps using the Extended DOS precluded the Extended Linux). So stick with 1 DOS/Windows partition. ================================================================================== xxxxxLATEK $LATEX LaTek LaTex (Macros for TeX no one uses TeX itself) Greek letters in LaTek Just Ω or &omega for capital or small omega. latex compile - Just "latex filename". (Assumed extension is tex, latex don't need to even enter it). Once it compiles, you'll get a DVI. LaTex postscript - To get postscript, type dvips -o summary.ps summary.dvi If just do dvips summary.dvi then it is sent immediately to lpr rather than having a .ps file created. view -- gs summary.ps To check a .dvi file in a terminal (no Xwindows) use dvitype dvitype -output-level=1 extended_standards.dvi If it runs, the dvi file is OK. LaTek summary Then - To get postscript, type dvips -o summary.ps summary.dvi gs summary.ps To use ghostscript - Just "gs Entire_Proposal.ps". It needs the .ps ghostscript Summary.pdf works too! xxxxxLINUXCONF=====RED HAT 7.3 SPECIFIC==================================== linuxconf IS NOT a default package installed in all distributions. Have to add it. When added, it will be added to /sbin subdirectory. http://www.solucorp.qc.ca/linuxconf/ is where to download. To install linuxconf .... rpm -i linuxconf-1.9r27.2-1.i386.rpm Better ftp-site for linuxconf. open ftp.xc.org user: anonymous password: e-mail address cd pub cd linuxconf cd devel Take the vanilla linuxconf (not X, not GUI, not tools, not utils). xxxxxLESS======================================== Great file viewer h -- bring up help /xxxx (find string xxxx) n (find it again) N (find it backwards) F (go to bottom of file, acts like tail -f) xxxxxLS======================================== LS -lS in /var/log to find giant log files ls -lSh gives human readable format (shows sizes in MByte, KBytes and Bytes) (The capital S sorts by size). man ls says ls -l does the following: print the file name, file type, permissions, number of hard links, owner name, group name, size in bytes, and timestamp The excerpts below from the / and /dev directories shows all the sorts of information you can get from ls -lSh cd / ; ls -lSh -rw-r--r-- 1 root root 9.9M Feb 21 06:52 stage1-x86-2004.3.tar.bz2 drwx------ 2 root root 16K Feb 21 06:21 lost+found drwxr-xr-x 2 root root 4.0K Feb 25 09:59 bin drwxr-xr-x 3 root root 4.0K Mar 23 17:24 boot Note the files are sorted by size and the size is in human readable form. cd /dev; ls -lSh Permissions ft? owner group #links timestamp lr-xr-xr-x 1 root root 10 May 23 10:48 adsp -> sound/adsp lr-xr-xr-x 1 root root 12 May 23 10:48 agpgart -> misc/agpgart lr-xr-xr-x 1 root root 11 May 23 10:48 audio -> sound/audio lr-xr-xr-x 1 root root 13 May 23 10:48 cdrom -> cdroms/cdrom0 Permissions ft? owner group Major, Minor timestamp crw------- 1 root root 5, 1 May 23 10:48 console lr-xr-xr-x 1 root root 8 May 23 10:48 fd0 -> floppy/0 .... lr-xr-xr-x 1 root root 34 May 23 10:48 sda1 -> scsi/host0/bus0/target0/lun0/part1 lr-xr-xr-x 1 root root 34 May 23 10:48 sda2 -> scsi/host0/bus0/target0/lun0/part2 lr-xr-xr-x 1 root root 34 May 23 10:48 sda3 -> scsi/host0/bus0/target0/lun0/part3 .... drwxr-xr-x 1 root root 0 Dec 31 1969 tts crw-rw-rw- 1 root root 5, 0 May 24 18:48 tty crw------- 1 richard root 188, 0 May 23 10:48 ttyUSB0 crw------- 1 richard root 188, 1 May 23 10:48 ttyUSB1 crw------- 1 richard root 188, 2 May 23 10:48 ttyUSB2 crw-r--r-- 1 root root 1, 9 May 23 10:48 urandom drwxr-xr-x 1 root root 0 Dec 31 1969 usb drwxr-xr-x 1 root root 0 Dec 31 1969 vc crw-rw-rw- 1 root root 1, 5 Dec 31 1969 zero Note the first character of each line: "l" is for link. (The directory or file that the link points to is shown with ->) "d" is for directory. "c" is interesting. The characters "c" and "b" are usually only found on files in the /dev directory, and they refer to "character" and "block" devices respectively. (You'd think that "sda1" would be a classic "block" device, but it appears to only be a link, see above) Character devices seem most common. Note that the ttys and consoles of the world are character devices, as are the USB devices. For devices, it appears that rather than listing # of hard links, the major, minor device #'s are listed. To create a directory, it's mkdir. To create a link ln. To create a character device, it's mknod -c /dev/devname Major, Minor. ========================================= xxxxxLIST AND KILL PROCESSES========================================= ps -Af to list all processes running with details. kill -9 pid to stop a rogue process. (kill and killall also work, but kill -9 is the toughest. It kills ANYTHING!) kill is recommended first because it allows processes to clean up, not just die like kill -9. ps aux or ps ax to see lots of processes by all users, roughly equal to ps -Af ps -ef is equivalent To check if ntpd is running, try: ps -A |grep -i ntpd Also try "top" which lists ALL processes and the memory consumed. xxxxxDISPLAY FREE / TOTAL MEMORY and DISK SPACE / DISK USAGE ========================================= free -- displays free and total memory cat /proc/meminfo -- Tells you more about current memory usage than you might want. df -h Tells about disk usage by partition du -hc breaks it down by directory and summarizes for each top-level directory du -hc /DATA would summarize all we had in /DATA xxxxxMAIL====================================== Mail is amazingly complicated. Sendmail is very large learning curve. Steve H. recommended exim. Arriving mail goes to /var/mail. It is then moved by an MTA (mail transfer agent) to the users root directory. Look for the conf file in /etc/exim/exim.conf Also -- From feynman I CAN send mail. Pine from Feynman correctly sends mail. Don't have to do anything special. /usr/sbin/sendmail seems to be my default mail handler. Actually -- If you want to send mail from one address, but have it look like it came from a different address, do the following: Fire up Pine. Select (S)etup, then (C)onfig. Press Ctrl-W to search for text, and type in "customized" and press enter. The option "customized-hdrs" will be highlighted. 'A' to add a value. Type in "Reply-To: rsonnenf@nmt.edu" (without the quotes) or "From: rsonnenf@nmt.edu" (without the quotes) and press enter. One changes reply-to address, other changes apparent message origin. xxxxxMINICOM====================================== minicom normally reads a startup file and sets defaults. However that can make it hang. minicom -s bypass the startup file and lets you set it up before it tries to connect. minicom -sm not only bypasses startup file but means you use Alt key instead of CtrlA key to access other commands. (It works better for me, I tend to lock up minicom with Ctrl-A key, don't know why!). Ctrl-Z-A. Hold Ctrl and Z, then release and quickly press A. Also ... change the default /dev/modem to /dev/ttyS0 (for COM1) communication. Turn of HW and SW flow control xxxxxMOUNTING A WINDOWS DRIVE========================================= To Mount the C-drive of Windows First create a mount point (Call it what you want, I'll use winc). cd /mnt mkdir winc [Only need to do this once] Then - As an SU mount -t msdos /dev/hda1 /mnt/winc Once this works, add a line to /etc/fstab /dev/hda1 /mnt/winc msdos defaults 0 0 Other people have recommended lines like the following: /dev/hda1 /mnt/windows vfat auto,owner,users,exec,rw 0 0 /dev/hdd5 /mnt/windows2 vfat auto,owner,users,exec,rw 0 0 For mounting two windows partitions on two different drives. cp temp.txt ./mnt/floppy/temp.txt To Browse the windows files. cd /mnt/winc then ls and cd from there Open explorer (say "Richard's Home" under Gnome). Then type / for top level, browse down thru the mount points and you'll get there! You might wonder how you go back and forth from your Windows drive to your linux drive. That's because you still have DOS reflexes. In linux, everything is a directory. Your native linux partitions are under /home (if that's how you set it up), but the windows stuff is under /mnt/winc. MORE ABOUT MOUNTING WINDOWS (or OTHER) The stated problem was a windows directory that was readable but NOT writeable. The key to the solution was the umask=0000 which gave all permissions to everyone. first un-mount umount /mnt/windows Then edit the entry in /etc/fstab Change from: /dev/hda1 /mnt/windows vfat defaults 0 0 To: /dev/hda1 /mnt/windows vfat rw,auto,umask=0000,users,exec 0 0 or /dev/hda1 /mnt/windows vfat defaults,umask=0000 0 0 Then mount the filesystem mount /mnt/windows I suppose that umask=002 did not help due to following: umask=002 (umask has inverse logic, so it tells which bits should *not* be masked unlike chmod that tells which bits should *be* masked) means the user and the group have all permisions and others not. Since you are *not * specifying the user and the group under whom's ID the filesystem shall be mounted, plus the mount option "defaults" contains automount, the filesystem is mounted as root and the root's default group which is also root. So when you try to access the filesystem as normal user, your write requests are masked out, since you are "others" (neither root nor belonging to the root group) BTW: I use 4 digits for umask. The first digit 0 indicates an octal number. The easiest way for an "alias" is a symbolic link: ln -s /mnt/windows /windows This will create an entry windows under / which is a symbolic link to /mnt/windows. So cd /windows will have the same result as if you would be executing cd /mnt/windows xxxxxMOUNTING AND USING FLOPPY DRIVES========================================= create a mount directory (/mnt/floppy) and then mount it. In many cases, the /mnt/floppy (or something similar) will already exist. Check it first. mount /dev/fd0 /mnt/floppy -t msdos [Run as root if needed] (fd0 is floppy drive "A:" from DOS, fd1 is "B:"). cd /mnt/floppy ls * cp /mnt/floppy/* . If do a df with floppy mounted, it Will tell you how much space is on floppy. It just works. Before popping floppy, do umount /dev/fd0 If get umount: /mnt/floppy: device is busy, it may be because your pwd is /mnt/floppy. mtools is an old set of linux tools that deals well with DOS floppies (it keeps long filenames and somehow encodes them onto floppy disks that only support short 8.3 names). Thus mcopy preserves a long filename, while cp does not. xxxxxMC========================================= Tagging a bunch of files in MC. Insert, C-t to tag files you may use the Insert key (the kich1 terminfo sequence) or the C-t (Control-t) sequence. To untag files, just retag a tagged file. Executing a command on the selected file. Type command (e.g. more) on command line, then Ctrl-M to paste selected file name xxxxxMOUNTING A CAMERA OR OTHER USB DRIVE========================================= Assuming that you see the device detected on boot: create a mount directory (/mnt/camera) and then mount it: mount /dev/sda1 /mnt/camera It may not be /dev/sda1 so if that doesn't work you'll have to check by using this command: tail -f /var/log/messages and find whether new device is sda1, sdb1, sdd1 etc. (What's cute about this is to start tail BEFORE plugging in device, then you see the message as you plug the device in.) For the flash reader on dirac mount /dev/sdc1 /mnt/flash -- of course, you need to do this as root. If the device has never been used before, try fdisk -p /dev/sdc (no 1). You'll probably see that it came with a FAT16 file system. xxxxxCREATING A FLASH FOR ESONDE========================================= Specifically for Prometheus flash -- Full procedure here: http://infohost.nmt.edu/~joeuser/research/Pebble/pebble_install_config.txt These instructions apply specifically for the flash reader attached to dirac. cd /mnt mkdir cf1; mkdir cf2 chmod 777 cf1; chmod 777 cf2 fdisk /dev/sdc Create two partitions. Here is what Prometheus flash partition table looks like on a 1 GByte flash Disk /dev/sdc: 1024 MB, 1024966656 bytes 32 heads, 63 sectors/track, 993 cylinders Units = cylinders of 2016 * 512 = 1032192 bytes Device Boot Start End Blocks Id System /dev/sdc1 1 79 79600+ 83 Linux /dev/sdc2 80 993 921312 83 Linux mkfs.ext2 /dev/sdc1 mkfs.ext2 /dev/sdc2 mount /dev/sdc1 /mnt/flash mount /dev/sdc2 /mnt/flash/wxdata #This trick allows cd to wxdata umount /mnt/flash/wxdata && umount /mnt/flash (or do it on two lines) xxxxxNEWBIE TRICKS ========================================= Newbietrick-A To see text that has scrolled off page in a command line, "Ctrl Pgup". Newbietrick-B Saving typing - Use "TAB" key to autocomplete filenames. Thus: nano joe will autocomplete nano joeswonderful.scientific.paper Newbietrick-C Remembering what command does what! First of all "man" command will explain them. Second, "info coreutils" has more on certain commands. Newbietrick-D Yes, but what was that command called? "apropos file" finds all commands related to files. Newbietrick-E Yes, but what was that command really called? If you can remember that it starts with an "l", type "l" it will show ALL commands that start with l. That ought to help. Even better, if you know it's lssomething, do ls and you'll see lsmod, for example. Newbietrick-F Running a program - Most Linux distros don't put current directory in your path, for security reasons. Thus to run myprog, type ./myprog. xxxxxNETWORK RESTART========DEBIAN SPECIFIC================================= For wireless network garage:/etc/init.d# /etc/init.d/pcmcia restart Shutting down PCMCIA services: cardmgr modules. Starting PCMCIA services: modules cardmgr. xxxxxMAIL FORWARDING / ALIASES AND PUBLIC LISTS =================================== Edit the file /etc/mail/aliases ... a sample of it is below: # Basic system aliases -- these MUST be present. MAILER-DAEMON: postmaster postmaster: root # General redirections for pseudo accounts. adm: root bin: root daemon: root Add the following lines -- phys321: gigigogo, tanutuva, joeuser, mattd AtmosElec: George, paul, john, ringo, vulcan Now if others send an e-mail to your machine to AtmosElec, your machine will automatically blast this back out to the addresses added. (Obviously mail services need to be running on your machine.) xxxxxMAKE ========================================= If you download a source package: .config creates a makefile according to your machine's archetecture. Now run make and then when that is done, run make install xxxxxMAN ========================================= man - Gives manual. To get out, Ctrl-Q, Ctrl-Y don't work. Ctrl-Z stops it, but have to kill it later. It just uses "less", and to get out, simply type "q" (not Ctrl-q). Using man -- man crontab will give you manual page for crontab ... but notice that "See Also" section has a second listing for crontab (crontab(5), whereas default is crontab(1). How do you see the 5 page listing? man crontab defaults to showing the 1 page listing. Use the -a option. man -a crontab will show the one page listing, but when you quit, will show the 5 page listing. xxxxxMATLAB========================================= Running Matlab as a client of TCC Running MATLAB from a vanilla Red-Hat distribution. ssh -ljoeuser -X cobra.nmt.edu (Also khaki was recommended, rainbow doesn't work) Cobra is in Speare5. Try underdog (confirmed), eldorado, oracle. Use the standard mail login for joeuser. There is nothing you need to setup about your -X windows system on your host. The -X seems to do it for you. It takes a while for Matlab to come up, then it just works! Don't use long filenames. How to kill a remote process? Right click on the box and say "Kill App". CTRL-Z to stop a process (have to kill it later). How to restart? How to spawn a new process? Troubles with matlab. I found that my license only likes to run for one user. Here is the workaround. Create one user (for example "langmuir") that will actually run Matlab. When setting up Matlab, configure to run for that user only. If have problems, erase all files in /var/tmp (because they indicate which user is trying to use the license). Also do a chmod +777 /var/tmp. There are also files in /usr/local/etc/matlab that indicate which users are allowed to run Matlab. They have been changed to only include "langmuir". Before running Matlab with gksu, need to logon as langmuir and issue an /usr/local/matlab/etc lmstart OR /usr/local/matlabR14/etc lmstart The magic formula ... from any user on pansy or slug, to do this: gksu -ulangmuir matlab. Here's what a normal start looks like: Checking license file for local hostname and local hostid . . . Taking down any existing license manager daemons . . . No license manager daemons running . . . Starting license manager . . . Debug logfile = /var/tmp/lm_TMW.log Other problems associated with being heisenberg and running MATLAB as langmuir. The owner of your scripts may not be you. So if you edit a script in an editor in one window, its owner becomes heisenberg. If create in Matlab, owner is langmuir. If try to edit script owned by heisenberg, it becomes read only. Other matlab problems. M file names can be long, but Matlab may only check uniqueness on first 8 characters. The type of message you get is undefined variable 'x' or class 'x' (if are trying to run a script x.m) Another way to get this error message seems to be to use _ character in m-file names. Printing from Matlab. Issues because are running as user other than langmuir. As root, I made all user directories writeable by all (chmod -R 777 *) or to make work and all subdirectories chmod -R +777 work. Need -R for recursive. Then direct printing didn't seem to work ... but printing to a file did. Print /home/heisenberg/fig1.ps then afterward lp fig1.ps. From Matlab command line, can print test and it automatically creates a test.ps. I think print -f2 test would create test.ps from figure2. gv works great on .ps files. PS files are not too large (couple hundred K). Seemed to have to explicitly type directory AND filename, matlab not smart enough to know where to put the file. Might change printcap again to change ps to Sandy so matlab will pick it up. Export to /home/langmuir/ seems to work. Loading files in Matlab test=load('test.csv'); If the first several lines of test CSV begin with %, then load works anyway and ignores these lines. Looks like % can be used anywhere in the data file. xxxxxGENERAL MATLAB NOTES -- ========================================= It's generally hard to find out what symbols are defined for plot. Here they are: . o x + * s d V ^ < > p h xxxxxMATLAB AND MEMORY -- ========================================= On Linux, swap space can be changed by using the mkswap and swapon commands. Also -- Matlab can EASILY use 2-3 GBytes of swap space and a Gig or more of RAM. So should always save about 3 GBytes for swap. (This is also near the 32-bit limit). To check swap space, do a cat /proc/swaps To see how Matlab is doing, use "top". Can also try feature('DumpMem') from Matlab command line (R14 and above) matlab -nojvm Seems to save memory by omitting the java virtual machine. You get "classic" MATLAB. Just a command box and the figures. No java displays or even the editor. xxxxxMATLAB UNINSTALLING -- ========================================= This is easy. First do an lmdown to stop lm. Then If Matlab is installed in /usr/bin/matlab7 do an rm -rf /usr/bin/matlab7 That's it! xxxxxMATLAB INSTALLING -- ========================================= Follow typical instructions for Unix (also avail on Mathworks website). Gotchas. 1) PERMISSION DENIED To run install, be in matlab directory on HDD and run /cdrom/install. Don't need install*, install is just fine. If you are not authorized to run install you will get an error message such as /cdrom/install: /cdrom/update/bin/glnx86/tsetup: Permission Denied. That permissions part is telling you that you've probably automounted your CD-ROM ro, without execute privileges, you need to be able to execute the install program from the CD. Here is what to do: When mounting the CD-ROM, care must be taken to ensure that the executable bit for the file system is set. The install instructions suggest (as root): mount -t iso9660 /dev/cdrom /mnt/cdrom This bypasses any configuration found in /etc/fstab and guarantees that the file system will have the exec bit set. If you want to use the configuration in /etc/fstab, and thus allow users to mount the CD-ROM (and be able to run binaries from the CD), you will need to add the "exec" option. Read the fine man pages for mount(8) and fstab(5) for more details. An example fstab entry might be: /dev/cdrom /cdrom iso9660 noauto,ro,user,exec 0 0 This will allow anyone to simply say "mount /cdrom" and then be able to run binaries from that CD-ROM. PLEASE NOTE: This may be considered to be a security hole, which is why we recommend bypassing fstab and using the full mount command as root instead. 2) Error message like LICENSE SERVER NOT STARTED, or INVALID LICENSE -- The license server needs to be running, even for a single-user non-networked license. You can start it manually, but better to add lines to your startup files so that it's always started. RTFM!! xxxxxNETWORK PERFORMANCE ========================================= Timing a file copy between two machines: Start a cron job that periodically copies a standard sized file. xxxxxNETWORK SETUP GENERAL ========================================= If want to bring up network from scratch w/o a reboot. Try the following. ifconfig eth0 192.168.0.10 netmask 255.255.255.0 up #Bring up card w/ ip address. You don't need to restart network after this. It should work immediately!! Some say that ifconfig eth0 192.168.0.10 is sufficient, w/o up or netmask. route add default gw 192.168.0.1 #Add default gateway #Add the nameservers You'll have to add your nameservers to /etc/resolv.conf and you should be set. A resolv.conf lines looks like: nameserver x.y.z.w rainbow 192.10.5.72 xxxxxNETWORK SETUP GENTOO========================================= /etc/hostname (contains hostname) heisenberg@dirac etc $ cat dnsdomainname nmt.edu heisenberg@dirac etc $ cat hostname dirac Haven't yet found a file like "interfaces" or "network" in gentoo. There is a file etc/network ... but it doesn't seem to be where the real action is. Maybe it's an alternate location. /etc/resolv.conf in gentoo has same function (DNSnameservers) as in redhat Can do the following in gentoo (I just don't know where the info is saved yet). Setting up your network consists of three steps. First we assign ourselves an IP address using ifconfig. Then we set up routing to the gateway using route. Then we finish up by placing the nameserver IPs in /etc/resolv.conf. To assign an IP address, you will need your IP address, broadcast address and netmask. Then execute the following command, substituting ${IP_ADDR} with your IP address, ${BROADCAST} with your broadcast address and ${NETMASK} with your netmask: # ifconfig eth0 ${IP_ADDR} broadcast ${BROADCAST} netmask ${NETMASK} up Now set up routing using route. Substitute ${GATEWAY} with your gateway IP address: # route add default gw ${GATEWAY} Now open /etc/resolv.conf with your favorite editor (in our example, we use nano): # nano -w /etc/resolv.conf Now fill in your nameserver(s) using the following as a template. Make sure you substitute ${NAMESERVER1} and ${NAMESERVER2} with the appropriate nameserver addresses: nameserver ${NAMESERVER1} nameserver ${NAMESERVER2} xxxxxNETWORK SETUP DEBIAN ========================================= # /etc/network/interfaces -- configuration file for ifup(8), ifdown(8) etc/network/interfaces in Debian plays the role of etc/sysconfig/network in Red Hat. On Hawk -- After editing /etc/hosts file to get the new names used do the following: hawk:/etc/init.d# ./dnsmasq stop Stopping caching dns forwarder: dnsmasq. hawk:/etc/init.d# ./dnsmasq start Starting caching dns forwarder: dnsmasq. xxxxxNTP ================================================================ For good docs on NTP, try http://tldp.org/HOWTO/TimePrecision-HOWTO/ntp.html (To understand interfacing of GPS -- See http://www.eecis.udel.edu/~mills/ntp/html/pps.html) If you want to get your clock close to correct before starting ntp, try ntpdate time.windows.com (or some other server). OR ntpdate time.nist.gov It fixes the clock right up, then start ntpd. (If already have ntpd running, I found ntpdate didn't work.) Here are the two servers I typically use: /usr/bin/ntpdate ntp.drydog.com (In Arizona -- Registered clockmaster@drydog.com) /usr/bin/ntpdate ntppub.tamu.edu (Texas A&M) College Station Texas Both of these are "stratum2" servers. The stratum1 servers are two highly loaded, even if more accurate. ntpdate typical errors: 1) richard@feynman richard $ ntpdate ntp.drydog.com Looking for host ntp.drydog.com and service ntp host found : shasta.drydog.com 29 May 00:02:45 ntpdate[1115]: bind() fails: Permission denied This means that I'm not root and not allowed to run this. (Not a useful error message) 2) root@feynman richard $ ntpdate ntp.drydog.com Looking for host ntp.drydog.com and service ntp host found : shasta.drydog.com 29 May 00:08:56 ntpdate[1213]: the NTP socket is in use, exiting This means I am already running ntpd. Need to kill it before running ntpdate. Use "setclock" on shutdown to synchronize hardware clock with systemclock. But probably not needed because that is automatic in modern Linuxes. The -x option in ntpd will cause slow slewing of time rather than stepwise correction. However slew rate is limited to 0.5 msec/s ... not good if are seconds off. In general for >128 ms error, time is stepped not slewed. To start ntp. Just ntpd (as root) uses file /etc/ntp.conf remote refid st t when poll reach delay offset jitter ============================================================================== *ntp3.tamu.edu 128.194.254.7 2 u 252 512 377 49.493 -26.758 1.733 +cpe-24-167-78-4 192.43.244.18 2 u 272 512 377 76.286 -30.196 2.226 +clock-a.develoo 192.12.19.20 2 u 276 512 377 72.646 -15.207 8.600 +shasta.drydog.c 164.67.62.194 2 u 306 512 377 82.940 -21.792 1.822 -65.75.183.220 204.123.2.5 2 u 269 512 107 76.818 -39.172 2.635 remote: Is the name of the remote NTP server. refid: Indicates where each server is getting its time right now. It can also be something like .GPS. For example, 192.43.244.18 is stratum 1 server time.nist.gov st: Stratum is a number from 1 to 16, to indicating remote server precision. 1 is the most accurate, 16 means 'server unreachable'. Your Stratum will be equal to the accurate remote server plus 1. poll: The polling interval (in seconds) between time requests. Initially the value will be smaller (32s) to allow synchronization to occur quickly. After the clocks are 'in sync' the polling value increases up to 1024 s to reduce load on popular time servers. reach: Octal representation of an array of 8 bits, representing the last 8 times the local machine tried to reach the server. The bit is set if the remote server was reached. Thus 377 means server was reached all 8 times. Note that server 65.75.183.220 was only being reached on 4 of last 8 tries. delay: The amount of time (seconds) needed to receive a response for a "what time is it" request. offset: The difference of time (millisec) between the local and remote server. In the course of synchronization, the offset time lowers down, indicating that the local machine is getting more accurate. Offset is in millisec. Thus 623564 is 623.564 seconds. If offset is > 1000 sec, ntpd will not start. jitter: Dispersion, also called Jitter, is a measure of the statistical variance of the offset across several successive request/response pairs. Lower dispersion values are preferred over higher dispersion values. Lower dispersions allow more accurate time synchronization. Jitter is in millisec. The meaning of the signs before server hostname - Means the local NTP service doesn't like this server very much + Means the local NTP service likes this server x Marks a bad host * Indicates the current favorite ntpq is command for messing with ntp. ntpq >clockvar can tell you where ntp is getting its time from (whether PPS, GPS serial or network). ntpq -p Shows all servers working ntpq -pn shows IP addresses To Install ntp DEBIAN / PEBBLE apt-get install ntp apt-get install ntp-doc apt-get install ntpdate -- Utility to set system time from network ntpdate -d is good to use. GENTOO emerge ntp To Start NTP automatically REDHAT Use chkconfig --level 2345 ntpd on To start ntpd on each reboot. (This could be generally useful -- But chkconfig is REDHAT specific and NOT Debian!) GENTOO rc-update add ntpd default < ntpq clockvar tells more xxxxxOOFFICE ================================================= Had some trouble with xoocalc. It only wanted to print certain pages. Question is how to set up for printing. Select View/Page Break Preview and only from within page break preview does a right click context menu come up showing "Define Print Range". You can't access it from under the print menu as you can in excel. xxxxxPCMCIA AND WIRELESS================DEBIAN SPECIFIC==================== To restart pcmcia services: /etc/rc.d/init.d/pcmcia start (or restart) /etc/init.d/pcmcia start /etc/init.d/pcmcia stop /etc/init.d/pcmcia restart To see all loaded modules: /sbin/lsmod To configure wireless "iwconfig" also route -n to trace a route. iwpriv eth1 gives a window into privileged wireless hardware setup (pretty specialized) xxxxxPASSWORD CHOICES=================== Use caps and lower case and #s. Be suspicious of specialized "extended ASCII" characters. They may appear one way in Windows and another in Linux. Post subject: Unable to su in fluxbox xterms [solved] Root can su to normal users, users that are members of the wheel group can su to root in a cli console, wheel group users can not su to root in an xterm (results in su: Authentication failure). Turns out it was simply an issue with my use of (extended) ascii characters in passwords. Removing (extended) ASCII chars solved the problem, so I'm assuming that i just needed a different character set for X.org xxxxxPRINTING MULTIPLE PAGES ON ONE=================== Use "psnup" to put out more than one logical page on a single physical page. e.g. psnup -2 | lpr -dMYPRINTER # Add a printer. xxxxxCUPS PRINTING =================== PRINTING from FEYNMAN I have tested feynman as follows. From within Acroread, you need to enter these commands exactly as below to print on remote printers. /usr/bin/lpr -Pkestrel (can use PS level 1) /usr/bin/lpr -Pdoublesided (Same as kestrel, but does doublesided ... but requires that you push a button first. So go there if are doing this. /usr/bin/lpr -Pcolorprinter (Gina office) Can use PS level 1 for BW, but for color need to use PS level 2 (selectable in printing box, for example from acrobat). This printer does not support PS level 3, and will give you an error if you use it. /usr/bin/lpr -Pupstairs (Dave Raymond ... for some reason, that printer does not work). Gentoo Printing Guide THere is much discussion of foomatic, but it's not needed, either to be installed or used. In fact, CUPS works fine, it just needs a HP6800.PPD file, which can be downloaded from linuxprinting.org. A PPD file tells printer how to best handle postscript. Content: 1. Installing CUPS (foomatic not needed) Setting up printing in Gentoo Linux is a relatively painless task, thanks to some great programs such as CUPS (the Common Unix Printing System) and foomatic. Both of these programs are currently in the Portage tree, and they are very easy to set up for the end user. Please be aware the cups is cross-desktop, i.e. you can follow these directions to get printing working under GNOME or KDE. There are other options, such as KDE's print setup, but I believe that CUPS is the easiest to setup, and the most scalable. Before emerging CUPS, it is a good idea to add the necessary USE flags to /etc/make.conf (as with ufed) add cups, foomaticdb, ppds and usb (if you are using a USB printer connection) to your existing USE var list. USE="cups foomaticdb ppds usb" Code Listing 1.2: Emerging necessary packages # emerge cups 2. Setting up Kernel Modules General Now that the necessary packages are installed, it is time to install the printer. Depending on what type of printer connection you will be using, it will be necessary to enable either parallel port or USB port printer connections in the kernel. Note: This is only needed for local printing. USB Modules To enable USB printer support, go to USB support and enable Support for USB and USB Printer support. Enabling them both as modules will install usbcore.o and printer.o in your modules directory. I suggest using modules because you won't have to restart your computer. Users of a 2.6 kernel will find these options under Device Drivers. After the kernel is built, and your computer restarted, it is time to load the necessary modules: Code Listing 2.1: Loading USB modules # modprobe usbcore (For 2.6 kernel users:) # modprobe usblp After the modules have loaded successfully, plug in the printer, and check dmesg to see if it was detected. Code Listing 2.2: Checking Kernel Messages # dmesg | tail You should see something like this: Code Listing 2.3: dmesg Output hub.c: USB new device connect on bus2/2, assigned device number 2 printer.c: usblp0: USB bidirectional printer dev 2 if 0 alt 1 proto 2 vid 0x03F0 pid 0x1104 Code Listing 2.5: Checking Kernel Messages # tail /var/log/messages Before setting up the printer with CUPS, we can test it with some simple low-level commands. Note: Some printers (especially the PPA-based ones like HP's 720 series, 820 series and 1000 series) don't accept ASCII-feed. If you have such a printer, remember that you have a PPA-based printer and that this test will fail even if the printer works. Note: Some printers (e.g. several HP LaserJets) need a ^L (Control-L) at the end of the file to trigger printing. Without the ^L the cat succeeds, but the printer absorbs the data, then sits and does nothing. Code Listing 2.7: Printer Testing Using cat # touch test.txt # echo "Hello World" > test.txt # cat test.txt > /dev/usb/lp0 3. Special Printer Drivers The following printing drivers are available as ebuilds in Portage: gimp-print, omni, hpijs, pnm2ppa. For most printers besides HP Inkjets, you will be able to use the standard Linux printer drivers. Visit the linuxprinting.org printer support database to find information on your specific printer. Make sure you read the documentation provided with any driver you download for installation and licensing information. If you are using an HP Inkjet printer, it is necessary to emerge the hpijs printer driver. This driver handles all of the Postscript interpretation necessary to make the HP printer work. The hpijs driver is for HP Inkjet printers only, but is available through Portage for your convenience. The documentation from HP for the hpijs driver will be placed in /usr/share/doc/hpijs-. The author highly recommends reading this. Code Listing 3.1: Emerging hpijs (hpijs is recommended (for example for the new HP6500 and 6800 series printers.) # emerge hpijs Note: If you are using a HP Laserjet, support may already be available via the GNOME printing system. If you are using a non HP Inkjet printer, you do not need to install this special printer driver. 4. PPD File Configuration Now it is time to configure the printer and CUPS. In order for your printer to interpret Postscript correctly, CUPS needs a PPD (Printer Postscript Definition) file. The easiest way to generate a PPD is through foomatic. Note: Another way is to download a PPD file from LinuxPrinting.org and place it in /usr/share/cups/model. I used this method of putting the .PPD directly in the model file. Code Listing 4.1: Starting cupsd # /etc/init.d/cupsd start 5. CUPS Configuration Since the printer itself is now configured, now CUPS must be setup to handle the printer queueing. CUPS can be accessed via web browser on port 631 of the printer server. CUPS has a built in configuration file for the daemon that should at least be modified to allow for URI-like device naming. Open up /etc/cups/cupsd.conf with your favorite editor and set FileDevice to Yes: Code Listing 5.1: Changing FileDevice to Yes # nano -w /etc/cups/cupsd.conf (Set FileDevice to Yes) For those who want to set up clients using the new print server please look in /etc/cupsd/client.conf on the client machine and point the ServerName parameter to the network name of the print server. Code Listing 5.2: Adding CUPS to default runlevel, and restarting CUPS # rc-update add cupsd default # /etc/init.d/cupsd restart The CUPS daemon should now be running, so open up your favorite browser, point it to http://localhost:631 and click on Manage Printer. Here you can find your newly installed printer, configure it or print a test page. Make sure you set the default page size to the page size you use (e.g. A4 instead of Letter). Note: If the printer does not work for some reason, go to the directory where you told your CUPS logs to be stored, and look through error_log. 6. Configuring programs to print using CUPS. General Most programs today have a native cups interface, so you need not change anything, just try to print in the program. The GIMP To be able to print documents using The Gimp, you have to (re)install the gimp package with the "gimpprint" USE variable enabled. This will install gimp-print if it isn't already done. Code Listing 6.1: Emerging gimp with printing capabilities (Be sure to have USE="gimpprint" enabled) # emerge gimp Now, open up The GIMP, and open an existing picture, or just some blank pic, it really doesn't matter because all we are looking for is the File menu. Right click on the image and go to File/Print The dialog for printing should come up, and when it does, click on new printer. If your printer is not already listed, type in the name of your printer, then select your printer type. Ok, you are now setup to print from The GIMP. Play with the settings and have some fun. 7. Configuring Windows to use the CUPS Printer Installing the Required Support In order for Windows to be able to use CUPS, you need to install IPP support. Windows 2000 and XP should have IPP support by default, Windows 98 and ME users will need to install it. Installing the CUPS Printer Fire up the Add Printer wizard and select Network Printer. When you're asked for the Printer URL, give the exact URL to the printer as you have defined it. Code Listing 7.1: Example URL for printer (This is an example) http://192.168.1.1:631/printers/Epson That's it! * visit http://localhost:631/admin and login as root (this is a good link to bookmark) * select "add printer" * enter name, location, and description (all of your choosing). Here is mine: o Name: hplj1200 o Location: Turlington 3355 o Description: Brian's Printer * the name can only contain letters, numbers, and underscores xxxxxPROC============================================= proc is amazing! The /proc directory, first of all, has a number of subdirectories. Each subdirectory has a number which is same as number of a currently running process. Within that directory itself are more files, each telling you something interesting about that process (memory usage, command line that launched it, environment variables etc.) For a great description or proc, go here: http://www.bb-zone.com/SLGFG/toc.html (Suse Linux Guide for Geeks) xxxxxPRINTING========================================= To cancel a job, use the "cancel" command. Easier though is to run gnome-cups-manager, select the printer and cancel print jobs as needed. lp is name of default postscript queue in Linux. Queue type is lpd. To check progress of print job, lpq. To print something lpr budget.ps Sandy's printer Laserjet 2200D on tern.nmt.edu scp budget.tex heisenberg@tern.nmt.edu:~ To copy to Sandy scp budget.tex heisenberg@tern.nmt.edu:~/e-sonde-proposal/. To copy to Sandy To set up printing on a machine with lpd already running (as opposed to cups) -- edit /etc/printcap (On red-hat machines, you edit /etc/printcap.local instead of /etc/printcap, but the syntax is the same.) #Fixed lp|Sandy's printer:\ <-- For Matlab otherwise it shows as "Remote Printer" lp|Remote printer entry:\ :lp=:\ :rm=tern.nmt.edu:\ :rp=lp:\ :sd=/var/spool/lpd/lp:\ :mx#0:\ :sh: kestrel|Remote printer entry:\ :lp=:\ :rm=kestrel.nmt.edu:\ :rp=lp:\ :sd=/var/spool/lpd/remote:\ :mx#0:\ :sh: pansey:/home/heisenberg# cd /etc pansey:/etc# pico printcap pansey:/etc# /etc/init.d/lpd restart Stopping printer spooler: lpd stop Starting printer spooler: lpd start pansey:/etc# lpq lp@tern 0 jobs pansey:/etc# lpq -Pkestrel lp@kestrel 0 jobs pansey:/etc# heisenberg@pansey:~$ lpr test.t heisenberg@pansey:~$ lpr -Pkestrel test.t Carlos Lopez Carillo's colorprinter setup # # physics office color laserjet # colorprinter:\ :lp=:rm=kestrel:rp=colorprinter:sd=/var/spool/lpd/colorprinter: REDHAT STUFF /etc/init.d/lpd restart doesn't work Use /sbin/service lpd restart instead Please start CUPS by running "/sbin/service cups start" as root. If you are currently running a different print server (such as LPRng), you may have to turn it off before CUPS can be started, e.g. by running "/sbin/service lpd stop" as root. To switch print systems permanently, use "/usr/sbin/alternatives --config print" SETTING UP CUPS on slug. I saw that cupsd was already running. I emerged gnome-cups-manager. After restarting CUPS I launched gnome-cups-manager. Select "New Printer" "Local" -- It detected my HP deskjet and I just set it up with standard PCL drivers (as a "new HP deskjet"). The "Network", type "LPD" (not CUPS -- in otherwords the remote computer is using lpd. Then The host is kestrel.nmt.edu and the Queue for the HPLJ2200D black-white printer is lp. For the HP4500DN colorprinter, the queue seems to be "colorprinter". The next step shows "Dymo labeler" ... that's a DEFAULT, not a misdetection! Select HP, then for the driver Laserjet Series Cups v1.1. Enter HPLJ2200D for printer name and description is not needed. It just all works!! To restart cups /etc/init.d/cupsd restart To add cups to gentoo xxxxxPYTHON SCRIPT LOGGING ======================================= Logging a python script (or ANY other Linux activity). Use the Linux "Script" utility. Usage: script log ... logs all activity at that terminal to a file called log until hit Ctrl-D or exit. script - make typescript of terminal session SYNOPSIS script [-a] [-f] [-q] [-t] [file] DESCRIPTION Script makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be printed out later with lpr(1). xxxxxRPM / APACHE=========RED HAT SPECIFIC================================ rpm - - help (that's two dashes, no space) rpm repository http://rufus.w3.org/linux/RPM Installing Apache rpm. su (If don't su, you get a mysterious message from installer "cannot get sole lock", but that's your problem). rpm -i apache-1.3.9-4.i386.rpm is how you install it If it asks for more libraries, go to RedHat downloads and look for "Libraries". (Not Development ... then only get debug versions!). rpm -qpil apache-1.3.9-4.i386.rpm Provides a lot of information /etc/httpd/conf .... /home/httpd /home/httpd/html ... /usr/sbin/httpd /usr/sbin/logresolve All of the above are the rpm telling you where it will put the software. Apache itself is httpd. Can run as follows /usr/bin/httpd, or by reboot because there will be a line in /etc/rc.d Make sure to configure /etc/httpd/conf/httpd.conf xxxxxRSYNC ====================================== Remote synchronization of different machines #rsync -avzn slug:/DATA/ /home/DATA --- To practice rsync -avz --progress slug:/DATA/ /home/DATA -a (archive ... preserves lots of info you'd want preserved) -v (verbose) -z (compress where possible to speed up) --progress (shows progress and data rate) Sync files on slug with current machine. /DATA is absolute data path. slug:DATA would be ~/DATA. Note that it matters what userid your are on local machine. If you are root on local, rsync assumes you are root on remote. If heisenberg on local, heisenberg on remote. rsync -avz --progress --exclude '.*' slug:/home/langmuir/ /home/langmuir --exclude '.*' doesn't sync all the . files, otherwise, backs up entire directory. --exclude "foo/" would exclude any directory called foo rsync -avzn --progress --exclude '.*' --exclude /home/george/wxdata/BalloonTX_UPAPP/TEST_DATA/ 'slug:/home/george/ /home/george To use rsync, no special installation is necessary ... except for having the command installed on both machines. xxxxxRUNLEVELS AND STARTUP ============DEBIAN ============================= Changing Runlevels: in /etc/inittab change the line id:5:initdefault: to id:3:initdefault: In fact, though Red Hat and most other distros go to runlevel 5 for the GUI, Debian does the GUI at runlevel 2. Thus 1 is multiuser command line and 2 is gui, and 3-5 don't do much and 6 is shutdown. ALSO -- The script /etc/init.d/rcS looks in the directory /etc/rc1.d, /etc/rc2.d ... whichever runlevel applies. These directories in turn contain nothing but symbolic links to scripts in init.d which are run in the numerical order of the links in rcX.d where S scripts are startup and K scripts are kill and they go in ascending numerical order!! So you should be able to turn off services by removing links from rc whatever.d xxxxxSTARTING UP / INITIALIZING ===========DEBIAN============================== /sbin/init runs first. It uses /etc/inittab which calls /etc/rc.d/rc.sysinit These run the scripts in the following directories /etc/rc.d/rc1.d /etc/rc.d/rc2.d /etc/rc.d/rc3.d (if only going to runlevel 3) /etc/rc.d/rc4.d /etc/rc.d/rc5.d ( if going to runlevel 5) "K" scripts are kill scripts, "S" scripts are start scripts. ========================================= xxxxxSCP SFTP ========================================= Would copy all files in local directory to remote directory of specified user. Particular file scp beef.h heisenberg@joeuser347.nmt.edu:dynamo/beef.h scp -p joeuser@cobra.nmt.edu:~/mail/read-messages-sep-2003 . ssh -l heisenberg joeuser347.nmt.edu scp *.* heisenberg@joeuser347.nmt.edu:dynamo/linux_debug/ scp Class_Projects joeuser@cobra.nmt.edu:~Class_Projects scp -pr heisenberg@sprite1.nmt.edu:/DATA . (r for recurse, p for preserve attributes) scp budget.tex heisenberg@tern.nmt.edu:~ To copy to Sandy scp budget.tex heisenberg@tern.nmt.edu:~/e-sonde-proposal/. scp heisenberg@129.138.mm.nn:"*.scr" . scp `ls *.eps` heisenberg@joeuser347.nmt.edu: Also, "sftp" would work too, then you just do "sftp heisenberg@zeus.nmt.edu" (give password) and say "put *.src" and that would/should work (works both ways, both get or put, similar to the old ftp). Or go to the other side and pull it in reverse. Or, the really geeky way would be to let the shell do the expansion for you: [heisenberg]$ scp `ls --color=no *.scr` heisenberg@zeus.nmt.edu: xxxxxSERIAL PORTS ========================================= To control an instrument with a serial port, cat 'command to send'> /dev/ttyS0... if you need to know more, read on! SETSERIAL garage:/home/heisenberg# setserial /dev/ttyS0 /dev/ttyS0, UART: 16550A, Port: 0x03f8, IRQ: 4 Can set a port to "low_latency" so CPU processes its characters more quickly. (Bogs down CPU more. OK in scientific apps.) read the multiple Serial port HOW-To's on tldp. They are extremely completee and easy to understand. Start here: http://www.tldp.org/HOWTO/Serial-HOWTO-10.html#ttySN_ Here is an excerpt of some of the best stuff. (Note devfs is a 2.4 kernel thing that applies to USB as well, but can still use the "old names" for serial ports) old old ISA IO dos devfs old name major minor address COM1 /dev/tts/0 /dev/ttyS0 4, 64; 3F8 COM2 /dev/tts/1 /dev/ttyS1 4, 65; 2F8 COM3 /dev/tts/2 /dev/ttyS2 4, 66; 3E8 COM4 /dev/tts/3 /dev/ttyS3 4, 67; 2E8 Send bytes to the port Labels are not apt to be definitive so here's another method. If the serial ports have been configured correctly per setserial, then you may send some bytes out a port and try to detect which connector (if any) it's coming out of. One way to send such a signal is to copy a long text file to the port using a command like: cp my_file_name /dev/ttyS1. A voltmeter connected to the DTR pin (see Serial-HOWTO for Pinout) will display a positive voltage as soon as you give the copy command. The transmit pin should go from several volts negative to a voltage fluctuating around zero after you start sending the bytes. If it doesn't (but the DTR went positive) then you've got the right port but it's blocked from sending. This may be due to a wrong IRQ, -clocal being set, etc. The command "stty -F /dev/ttyS1 -a" should show clocal (and not -clocal). If not, change it to clocal. xxxxxSHELLS ========================================= # To run this, type "bash temp.txt" #cd /home/heisenberg/win_backup/aainfors/Tech/Dynamo/Proposal #cd "Selected earlier vers for reference" cd /home/heisenberg/win_backup/aainfors/Tech/Langmuir/DropSonde echo hi gnome-terminal --background yellow --foreground black xxxxxSLEEP ========================================= Delay wait pause -- If you are used to pause or delay or wait in other OS's, in Linux it's sleep. sleep 2 .... delay for 2 seconds. xxxxxSSH ========================================= ssh -ljoeuser rainbow.nmt.edu ssh -X -ljoeuser rainbow.nmt.edu -- forwards any X sessions to local display. Could be used with Matlab, for example. Alternate form of ssh omits the -l ssh joeuser@rainbow.nmt.edu works great! ssh-keygen can be used to create keys on both client and server sides Checking which libraries you are running? How to actually make cron do something? ssh without need for Password. Use ssh-keygen -t rsa to save a local copy of your public and private keys. Then put your public key on the target machine under authorized_keys. Then it just works! I'm running Red Hat 6.0, and I'm trying to redirect my telnet stdin from a file. Whenever I use either a pipe or < input, the client connects, informs me that the escape is ^], and says the remote server has closed the connection. What's wrong? Example: $ telnet csmith < input.txt Christopher Smith I've seen examples of telnet scripting being done this way. However, I think it probably depends on the version of telnet that you're using and there is a better way. For example when I do an strace on my copy of telnet I find a number of system calls like: ioctl(0, SNDCTL_TMR_STOP, {B134 -opost -isig -icanon echo ...}) = -1 ENOTTY (Inappropriate ioctl for device) This suggests that telnet is detecting that its input file handle is not a terminal device, and is bailing at that point. (It would be nice if it gave an error message a unique error code and if they listed this constraint in their man pages). Anyway, simple redirection is not the way to run interactive programs like telnet under scripted control. You probably want to use the 'expect' scripting language instead. `HELP: Crontab not running From Richard N. Turner on Sat, 09 Sep 2000 Dear Editor, I saw the article mentioned in the subject and some of the followups and had to reply. I've seen more than my share of people cursing cron and saying: "But the script runs fine from the command line!". Pierre Abbat's reply in the September issue was right on. Most people will modify the PATH variable to include some directories beyond the major ones that get defined in places like /etc/profile and scripts will fail when they attempt to run some commands that rely on this modified PATH. The thing to remember is that cron doesn't run your .profile when it runs a script. If you don't explicitly define the full path to a program run from within the script it'll fail. So you either have to make sure your script contains something like "/home/mydir/devel/bin/prog1" (or whatever) or amend the PATH at the top of the script. Another alternative is to just source, depending on your shell, either .profile or .bash_profile from within your script (assuming that it defines PATH and whatever other environment variables were helping the script run from the command line). If you include a line near the top of your script like: . /home/mydir/.profile or . /home/mydir/.bash_profile all things you usually rely on in your interactive environment are defined for your scripts run under cron as well. If you do decide to source your .profile, you might want to watch for things that depend on there being a display and/or keyboard "attached" to the process running the script. If there isn't, you might see strange error messages like "not a typewriter" or "cannot open display :0.0". I have a toolbox of variables and shell functions that I like to use in a file called "std_functions" which I source near the beginning of my interactive environment setup as well as my scripts. One of the things I put in `std_functions' is: TRUE="0 -eq 0" #Lets you define Boolean environment variables and FALSE="1 -eq 0" #makes scripts easier to read six months from now. if [ -t 0 ] then INTERACTIVE=${TRUE} else INTERACTIVE=${FALSE} fi The "-t" test returns `true' if stdin (file handle 0) is associated with a terminal. Then in your profile, you can do things like run xrdb using: if [ ${INTERACTIVE} ] then xrdb -l ~.Xresources fi and not get weird messages from your cron jobs (The above `if' block would, of course, evaluate as false under cron). I tend to keep my profile arranged so that any setup that I need for my interactive sessions is wrapped by an if-then-fi block. After all, you don't really need to define aliases and use them in your shell scripts (Ugh!). Hope this'll help someone... xxxxxSSH==ghostview or gv======================================= To look at pdfs in Linux. Use Ghostview (gv). Have verified the following works just as written. ssh -ljoeuser -X cobra.nmt.edu gv or gv test.eps works great. Had trouble w/ tif and .jpg From within gv, PrintAll. Then print command is lpr -PHPLJ2200D to print to remote printer or lp or lpr alone to print to local (default) printer lp file.txt or lpr file.txt work just great to print to my local printer. netscape -- Both work just fine. xxxxxSYSTEM ERRORS AND SYSTEM LOGS=======DEBIAN SPECIFIC================================= Look in /var/log to find system log called "messages" and also to run command /var/log/DMESG, which shows every message from current boot. /proc/interrupts (lists all used interrupts) /proc/config.opts (allows one to exclude certain interrupts from PCI autoassign). /proc/cpuinfo, /proc/uptime, /proc/partitions, /proc/interrupts ... all obvious and all useful! Kmsg . logs kernel messages. /var/log/messages . puts a mark every 20 mins so you can tell about when a system crashed. Also shows ALL boot messages and all error messages. /var/log/daemon.log /var/log/lpd.log every print job /var/log/auth.log . security /proc/net/dev has a list of all the packets and errors received by all network devices. xxxxxSWAP== swapfiles ======================================= You want a swapfile in Linux. I've found I can use 2 or even 4 GBytes if doing a lot of number crunching in matlab. At least make it 2X as large as your installed memory. In fdisk, you usually choose type "82" (linux swap) You need a "swap" line in your /etc/fstab When you are setting up a system, you need mkswap, followed by swapon -a (-a activates all swaps in the fstab) To add a swap file: 1. Determine the size of the new swap file and multiple by 1024 to determine the block size. For example, the block size of a 64 MB swap file is 65536. A 3 GByte swap is 3000000 (approx). 2. At a shell prompt as root, type the following command with count being equal to the desired block size: dd if=/dev/zero of=/swapfile bs=1024 count=3100000 3100000+0 records in 3100000+0 records out (Took a couple of minutes) 3. Setup the swap file with the command:mkswap /swapfile Setting up swapspace version 1, size = 3174395 kB 4. To enable the swap file immediately but not automatically at boot time: swapon /swapfile (This isn't instantaneous either!) If alreay have a swapfile running, the swap space will be additive. 5. To enable it at boot time, edit /etc/fstab to include: /swapfile swap swap defaults 0 0 The next time the system boots, it will enable the new swap file. 6. After adding the new swap file and enabling it, make sure it is enabled by viewing the output of the command cat /proc/swaps or free. xxxxxTAIL ======================================== tail -f messages -- Lets you print the final lines of any error logs . thus you can see the new errors coming in real time even if not at console. (see HEAD) xxxxxTAR GZIP BZ2 etc.========================================= Tar can do most of what you need to unzip archives. For example tar -xjf yourfile will run the decompression for bz2 (bzip2) files. tar -xzvf yourfile will handle gzip and there is lots more! Also: gzip -h (help) gzip -d * (will decompress all .zip files in current directory) xxxxxTRUNCATING a file (basic VI) ============================= vi file (or vim file). :100 (go to line 100) :+100 go another 100 lines down :d 1000 (delete 1000 lines) :w (write file out) :q (quit) :q! (quit with over-ride) :wq is also allowed These commands can be done w/o :, but then cut text goes in a buffer. Actually vi doesn't seem so bad ... Can use arrows to bring cursor to where want to edit. Hitting "a" puts you in insert mode. Type what you want. The "Esc" to get back to command mode. xxxxxTIMING a file copy between two machines: ====================================== time scp (for example) will give the time to execute the command. Can also call DATE %s to give an argument in seconds or DATE "%h %H %M %S %s" scp does not want to take input (e.g. a password) from anything but keyboard (no redirection allowed). However the -B option suppresses output, and if use (via ssh-keygen) a matched key on host and client, then a password isn't necessary. xxxxxUNAME ========================================= uname -a -- Which version of Linux are you running? Via chipset wants .Pentium Classic. versions of Debian Linux. 2.4 is stable version, 2.5 is test version. xxxxxVIEWING FILETYPES ========================================= Viewing different type of files. For .PS and .EPS, use gv. For pdfs, use xpdf. (or gpdf). Acrobat is also avail, but not necessary. For jpg use xv. To understand what type of File something is, type "File" xxxxxWHICH / WHEREIS ========================================= find / -name rc*.d find is completely general (like old DOS Whereis) To find a command which, e.g. which rpm, which tar To find a file whereis (start in root directory in this case ... and recurse). Which has a hard-coded search path, good for finding commands, but not guaranteed to find everything on the machine. To find a program to run, try whereis program. If only get Program: ... then it wasn't found. xxxxxXWINDOWS ========================================= Xconfigurator - Use it WHENEVER you change anything about the display (like the monitor, or the videocard). Go back to Runlevel 3 before you do this if you can so that you'll come up in text mode. Don't run Xconfigurator when already running Xwindows ... it can make a mess. /usr/X11R6/bin/xf86config - Changing monitor resolution / display resolution. Use ctrl-alt+ to cycle through all different display options (Use + on the numeric keypad). These are the options you set as possibilities in Xconfigurator. There are tricks to be running an X-app on one machine and see results on a remote machine. Something like this: I type "xhost +192.168.0.3" to allow Xapps to connect to the client_pc1 I then "ssh 192.168.0.3 -l my_UID" to connect to server_pc2. I type "export DISPLAY=192.168.0.2:0" to export my Xapps from the server to the client_pc1. I type "echo $DISPLAY" and it confirms my Xapps should redirect ok. Serviceconf (type it at the command line, or find it under the Gnome/ Programs / System / Serviceconf) Xwindows Config ============================= Xwindows fails for failure to install proper driver. Determine driver type from looking at video card and video chip. Use VESA or SVGA or VGA if can't figure out more specific info. Use dselect Type /xserver when get to packages screen (to jump to the xservers). Pick one based on chipset. It will run config script after download and install the xserver. If blow it and need to run again, type dpkg-reconfigure xserverpackagenamegoeshere OR dpkg-reconfigure --all Setting an Xterm at a particular size without another window manager. cat > /etc/X11/gdm/Sessions/xterm exec /usr/X11R6/bin/xterm chmod +x /etc/X11/gdm/Sessions/xterm Additionally , you can add something like -geometry 120x60 to control its dimensions. Keep in mind though, without a window manager, you cant resize the xterm or anything at all. When you quit the xterm ( exit, logout, Ctrl-D) the X session will end. MULTIPLE X-Sessions with Different Video Resolutions========================== I have seen others use a command like "startx -- :1 -depth 16 -xf86config XF86Config-4.16bpp" to change their color depth and switch to the 24bit color by press the Ctrl-Alt-F7. If two people are sharing a computer and one of them is running X, From command line or console you can startx -- :1 & starts another Xwindows session. Display switching: Ctrl-Alt-F8, Alt-F8. (Can always use Ctrl-Alt-F1..F8) What you have observed is someone starting a second X session with a customized configuration file (specified with the -xf86config XF86Config-4.16bpp argument) to run at 16bpp. They are able to then switch back to their original (24bpp) X session with the Ctrl-Alt-F7 keystroke sequence. They can switch to the 16bpp session with a Ctrl-Alt-F8 keystroke sequence, similarly to the way they switched to the non-X terminal session they used to invoke the second X session with a Ctrl-Alt-F1 keystroke sequence. /etc/X11/XF86Config ============================= Here is a section of that file: # The accelerated servers (S3, Mach32, Mach8, 8514, P9000, AGX, W32, Mach64 # I128, and S3V) Section "Screen" Driver "accel" Device "ATI Mach64" Monitor "Optiquest Q71" DefaultColorDepth 16 -- Because set to 16, the Section I have marked with &&&& is what is used. If depth was 8-bit, it would use previous section. Subsection "Display" Depth 8 Modes "1152x864" "1024x768" "800x600" # The previous line means 1152x864 is the mode it boots in, move that to # end of list or remove it if want to start with 1024x768. ViewPort 0 0 EndSubsection &&& Subsection "Display" Depth 16 Modes "800x600" "640x480" ViewPort 0 0 xxxxxXVIEW Tricks ============================= Use xview (or xv). Right click on image once it is loaded to bring up a control panel (e.g. to print!). "Try Autofit" to make it exactly fit on page. Click Letter "A" to create Text. Then move it, then click the paste icon (looks like two pieces of paper) to paste the text in place. Then Save. It works. Don't know how to adjust text size. xxxxxVI Tutorial ============================= Vi Tutorial EXAMPLES: :%s/ASCII/NEW_ASCII/g Change ASCII to NEW_ASCII throughout a file :1,3s/dog/cat Replace first occurence of dog on first 3 lines with cat :1,61s/./##. My file has 61 lines. Replace first . with ##. on each line. 1. Modes Vi uses a modal system of editing, the two modes are command mode and insert mode. The editor initially comes up on command mode. * These commands move you from command mode to insert mode. a append after cursor A append at end of line c begin change operation C change to end of line i insert before cursor I insert at end of line o open a line below current line O open a line above current line R begin overwriting text s substitute a character S substitute an entire line * The key moves you from insert mode to command mode. As a general rule it is a good habit to get into to remain in command mode except when you are actually typing in text. Learn to automatically hit each time you finish editing. Note: You can configure vi to display whether you are in insert mode or command mode. From command mode (the default when vi starts) type in: :set showmode 2. Starting vi vi begin editing unnamed file vi file1 begin editing file1 vi file1 file2 file3 begin editing 3 files, file1 will appear initially vi *.txt begin editing all files ending in '.txt' vi -r important.file view file 'important.file' in read-only mode Related Commands Note that the following commands are to be executed from command mode * If you started vi with more than 1 file name on the command line, you can type: :n to go to the next file in the list of files you supplied. * If you have entered :n one or more times to move through a list of files, you can return to the first file (the initial file that appeared when you started vi) by typing: :rew * You can list all the files that you gave vi on the command line (the current file will appear inside '[' ']') using the following command: :args * Once vi is running, you can jump directly to a new file by typing: :e the.new.file.name * While you are running vi, if you have changed the current file via: :rew, :e, :n you can swap back to the previous file using: :e# This is especially useful when you are entering long pathnames after :e 3. Leaving vi Note: the following commands are all executable only from command mode :q quit (assumes no changes made) :q! quit, discard any changes that were made :wq write the file, then quit ZZ write the file, then quit :w newname write the file to 'newname' :w writes the current file to disk w/o exiting vi 4. Insert Mode, the most useful commands * i (insert text before the cursor) This is the command you will use most often. Adds new text before the character above the cursor. * a (insert text after the cursor) This command is most useful when your cursor is at the end of a line and you wish to add more text. The i command can be used as a substitute for a (by repositioning the cursor) in all other situations, but a is a necessity for the above situation. * A (insert text at end of line) Most useful when your cursor is in the middle of a line and you wish to add text to the next line. Use A to achieve this effect. * cw (change word) suppose you have a line of text: Now is the thyme for all good men ... move your cursor to the 't' in thyme and type cw, you will see: Now is the thym$ for all good men ... Type in 'time' and then hit , the line will be corrected. * R (replace text) most useful when the number of characters you want to replace is the same as the current number of characters. For example: The untied states of america 5. Command Mode, navigating the current file Although the and and arrow keys work on some systems, I would strongly discourage their use. The following commands are guaranteed to work properly on all systems. Action vi equivalent Page Up ^F Page Down ^B Left Arrow h Right Arrow l Up Arrow k Down Arrow j Home 0 End $ 6. Command Mode, deleting text Action vi equivalent delete current line dd delete from cursor to end of line D delete character under cursor x delete character before cursor (backspace) X Note that many of the above commands can be preceeded by a number, for example: * 9x delete 9 characters * 3dd delete 3 lines 7. Command Mode, line numbers Action vi equivalent show line numbers :set nu turn off line numbers :set nonu display current line number/file name ^g go to line number (1 for example) :1 go to last line in file G 8. Command Mode, cutting, copying and pasting Action vi equivalent copy current line to "clipboard" yy paste contents of "clipboard" below current line p paste contents of "clipboard" above current line P copy current line, and next 4 lines to "clipboard" 5yy write lines 200 -> 205 to temp.file :200,205w temp.file write lines 100 -> end of file to temp.file :100,$w temp.file write current line -> line 300 to temp.file :.,300w temp.file write current line and the next 3 lines to temp.file :.,.+3w temp.file write lines 200 -> next to last line of the file to temp.file :200, $-1w temp.file read contents of temp.file into current file :r temp.file 9. Command Mode, searching Action vi equivalent set case insensitive search :set ic set case sensitive search :set noic search forward (down) for "hello" /hello search backward (up) for "hello" ?hello search again, (same direction as original) n search again, (opposite direction as original) N search for "hello" at start of a line /^hello search for "hello" at end of a line /hello$ search for "hello" or "Hello" /[hH]ello search for "int" as a word (i.e. not print or sprint) /\<int\> search for "eat" but not "beat" or "neat" /\[^bn]eat 10. Command Mode, replacing / changing text Action vi equivalent replace "dog" with "cat" (first occurrence of dog) on the current line :s/dog/cat replace "dog" with "cat" on lines 1 -> 3 (first occurrence of dog on each line) of the file :1,3s/dog/cat replace "dog" with "cat" on lines 1 -> 3 of the file, every occurrence :1,3s/dog/cat/g replace "dog" with "cat" (every occurrence) for the entire file :1,$s/dog/cat/g replace "dog" with "cat" (every occurrence) for the entire file (alternative method) :%s/dog/cat/g replace "dog" with "cat" (every occurrence) for the entire file but confirm each replacement :%s/dog/cat/gc 11. Command Mode, swapping commands Action vi equivalent swap two letters (i.e. cta -> cat) note that the cursor must be on the first of the two letters xp swap two lines (swaps current line with the line below it) ddp 12. Command Mode, other useful commands * u and U, undo commands. u undoes the last action performed, U restores the current line to its original state (when the cursor first was put on that line) * :g, the "global" command. Most useful for performing a deletion on lines that match a certain pattern. delete all lines containing "dog" :g/dog/d delete all blank lines :g/^$/d * J, the join command. Use this command to cause the next line to be joined to the end of the current line. * m, the mark command. Suppose you are editing a large text file and you wish to be able to mark your place at several spots in the file and return to them immediately. mark the current line as "line a" ma mark the current line as "line b" mb return to the line marked "a" 'a write all lines between mark "a" and mark "b" to temp.file :'a,'bw temp.file * %, the "pair matching" command. If you put your cursor on a '[', '{', or '(' character when you type % the cursor will jump to the matching ']', '}' or ')' character. * ., the "do it again" command. Suppose you have two lines of text: here is line one here is line two you change the first line to read Here is line one Put your cursor on the "here" of "here is line two" and type ., the same change will be repeated. The dot command is extremely powerful. It can be used to "do it again" with a surprising number of vi editing commands * &, the "do that substitution again" command. Suppose you have a line that reads: rats live on no evil star you type: :s/rats/bats changing the line to: bats live on no evil star then you move your cursor to another line reading: rats, rats, rats! when you type & you'll see bats, rats, rats! pressing & twice more will convert "rats" to "bats" for the entire line * ~, the "reverse case" command. If you have a line that reads: i am shouting placing your cursor on the initial 'i' and holding down the ~ key results in: I AM SHOUTING * f, the "find within a line" command. Suppose your cursor is on the first 'I' on the following line. I think therefore I am you wish to change "am" into "spam" You type fa which puts your cursor directly on the 'a' in 'am' Note that F searches to the left (f searches to the right). Also ; searches for subsequent matching characters (next occurrence) and , searches for the next match in the opposite direction of the initial search. * w, the "move by words" command. Useful to move your cursor to the right on a line, a word at a time. Note that w considers punctuation characters as words, you can also use W which only considers whitespace in determining the next word. * using "named" buffers this technique is primarily useful for copying lines of text from one file to another. If you use dd or yy to cut/copy a line of text then use :e to open a new file, you will find that the "clipboard" no longer contains the text you saved. To solve this problem, save your text in a "named" buffer. "a10yy :e temp.file "ap copies 10 lines into the named buffer "a" then puts the contents of buffer "a" into the newly opened temp.file. the only real difference between using yy or dd with named buffers is you preceed the command with " then the buffer name (a-z) * command mapping this can be used to make a "macro" for a series of keystrokes. It is a good idea to map your macros to unused letters (see below for a table of unused letters). Note that to use "special" keys ( and ) for example in a macro, you must type ^v before the special character. map '>' to "indent the current line by 3 spaces" :map > :s/^/ /^M Note that the ^M is formed by typing: ^v map 'q' to make a copy of the current line and append it to itself :map q yyPJ To turn off a mapping we created: :unmap q To list all the current mappings: :map * abbreviations used to make abbreviations for long, frequently typed phrases You type: :ab zgs Zeh Graphics Systems, Inc. then while editing you type: I work for zgs The line expands to: I work for Zeh Graphics Systems, Inc. To turn off the abbreviation we just created: :unab zgs To list all current abbreviations :ab 13. Table of unused letters/symbols Letters: g, K, q, V, v Control keys: ^a, ^k, ^o, ^t, ^w, ^x Symbols: _, *, \, = 14. The .exrc file Located in your home directory ($HOME). This file allows you to customize your vi environment, and preserve your settings between sessions. Note that although the set and map commands are preceeded by a : when we enter them directly in vi, they have not starting : in the .exrc file. Here is an example .exrc file """"""""""""""""""""""""""""""""""""""""""""""""""""""""" " Note that a " at the start of a line is a comment in " the .exrc file """"""""""""""""""""""""""""""""""""""""""""""""""""""""" " Map [>] to [Indent current line by 3 spaces] map > :s/^/ /^M " Map [<] to [Delete all spaces / tabs from the beginning " of the current line] map < :s/^[ ]*//^M " enable mode (input/command) display set showmode " default to ignore case for all searching set ic