Unix Tips

  1. Good Unix Links
  2. Using the bulletin boards from a Statistics account
  3. Find files with forgotten names/locations
  4. Make postscript active in Netscape
  5. Print several pages per sheet of paper
  6. Print in reverse order
  7. Customize your Linux GUI
  8. Set a default printer
  9. Fix weird keyboard problems
  10. Kill garbage characters in a file (e.g. ^M)
  11. Search for unix commands
  12. Make a shortcut for a command
  13. UnPack tar and/or Compressed files
  14. Pack files into a tar file and compress them
  15. Use 2 windows in emacs
  16. Working with columns in emacs
  17. Make screen snapshots
  18. Connect to Andrew
  19. Beep on mail arrival
  20. Forward Andrew mail
  21. Setup mail for vacation message
  22. Use jukeboxes
  23. Make graph paper
  24. View MS Word or Excel documents
  25. Find text in all .tex documents
  26. Loop through numbered files in a shell script
  27. Remote access to Andrew from Stat (e.g., for SAS)

  1. How do I use the b-boards from my Stat account?
    1. Authenticate to Andrew by typing "klog", pressing Enter, and entering your Andrew password.
    2. Type messages& to get into the bulletin boards.
    3. Choose More.../Message Folders/Read By Name then enter a b-board name, e.g. "cmu.misc.market". A list of top-level bulletin boards available on Andrew is at http://www.cmu.edu/computing/freshstart/mail.html. Now the middle window shows the message headers for that b-board.
    4. Choose Search/Captions backward and enter a search term. Click on the first match in the middle window to read the message text in the bottom window.
    5. You can use control-r/Enter to repeat the search for earlier messages. You have to click on the header in the middle window to update the message text in the lower window. (control-s/Enter searches forward.)
    6. Use message/Quit to quit.

  2. Can't remember what your file was called? Go to some directory not below where the file might be, but as far down the directory tree as possible (for speed), (e.g. type cd Stat701). If you remember that the letters "HW" are in the file name, type ffind hw, which searches all file names starting at the current directory and working downward, ignoring upper/lower case differences, and prints out all file names containing those characters.
    If you just want to find a directory containing some letters, use "dfind".
    If you totally forget the file name, and need to find it badly, you can search every line of every file for text inside files using "tfind".
    Alternatively use newfiles to list all files created or modified today, or e.g. old 3 to list all files created or modified three days ago.
    Currently the "*find" commands do NOT handle embedded spaces or special characters like ">"" or "<". Also they are interruptible with control-c.
    The files are here: ffind , dfind , tfind , newfiles , old.
    You should put these files somewhere in your PATH, e.g. in "/bin".
    Another simple alternative is illustrated here. Assume we want to find a file with the letters "HW" in the filename. Use:
         find ~ -name "*HW*"
         
    or:
         find , -name "*HW*"
         
    depending on whether you want the search to start in your root or the current directory.

  3. The unix program psnup allow printing of the pages in a postscript file in reduced form with several original pages on each printout page. E.g. to print the file mylecture.ps with 4 pages per sheet on the printer names stain, type psnup -4 mylecture.ps | stain at the unix prompt. If you prefer a new postscript file, use psnup -4 mylecture.ps > lectureX4.ps instead.

  4. In Netscape, when you click on a postscript or adobe acrobat file link, do you get a file save dialog? If so, do the following in Netscape:
    1. Choose Edit / preferences
    2. Click on the arrow next to Navigator
    3. Choose applications / click New
    4. Fill in Description: Postscript Document
      MIME: application/postscript
      Sufixes: ps
    5. Click next to application and fill in ghostview %s
    6. Click OK/OK

  5. Want to print in reverse order so you don't have to reshuffle your output? Try psselect -r test.ps | stain to print test.ps in reverse order on printer stain.

  6. Want to customize your Linux GUI? Look at the Linux Manuals .

  7. In various programs do you have to keep entering the name of your printer? To make e.g. smear your default printer, put the following two lines in your .login file:

         setenv PRINTER smear
         setenv LPDEST $PRINTER
         
  8. Do you have weird keyboard problems such as, you can't get "@" in your mailer, or can't use backspace to erase one character? The problem is probably in your "stty" settings. The easiest way to fix this is to put something like the following in the ".cshrc" file in your home directory.
         stty erase '^h' kill '^x' intr '^c'
         
  9. Want to remove unwanted characters from a file in emacs? If you see control characters in your file (e.g. ^M in a file transferred from a DOS system) you can remove them by combining the emacs "search and replace" function with the "quote" function. To replace "^M" with carriage return or a blank, type Esc % to activate "Query replace", type Ctrl-q Ctrl-m Enter to specify what you are searching for, after seeing "with:", type Ctrl-q Ctrl-j Enter to replace with a carriage return or Enter to just eliminate the funny character, and finally press ! to replace all occurrances.

    If the weird character shows up in the form "\245" you will need to first create a new file with the "\245"s replaced with "^M"s. To create File2.txt from File1.txt while replacing "\245" with "^M", use the Unix command cat File1.txt|tr "\245" "\015">File2.txt.

  10. Don't know/forgot how do do something? Use apropos and man. E.g. if you don't know how two compare to files to see if they are identical, type apropos compare. Look for entries followed by "(1)"; these are Unix commands. You will find "cmp(1)" on the list. Then type man cmp to see that cmp file1 file2 compares "file1" to "file2". My about is better than apropos.

  11. Want a shortcut for starting a program? Put an alias in your ".cshrc" file. E.g. alias sp Splus -e makes Unix interpret "sp" as "Splus -e". To check what an alias will do, or to check if something is already in use as an alias or existing program, use which. E.g. on my system, which sp responds "sp: aliased to Splus -e"; which mv responds "/bin/mv" to tell me that "mv" is a program located in the "/bin" directory; and which a responds "a: Command not found" to tell me that "a" is not in use.

  12. How do I unpack/extract the files in a .tar file that I downloaded? If the file ends with ".Z" or ".gz", first unzip/uncompress it with gunzip file.tar.Z or uncompress file.tar.Z to create the plain "tar" file. Then execute tar xvf file.tar to extract all of the files inside the tar file. Then read the README file. You may, e.g., need to run "make" or carry out other steps described in the README.
    Also note that tar tvf myfile.tar shows the contents of the tar file without extracting anything.

  13. How to I pack files into a tar file and compress them? To pack up all or some of the files in a directory into a single small file, get into the directory using cd, then execute, e.g., tar cvf myfile.tar * or tar cvf myfile.tar *.dat to pack the specified files into myfile.tar. Use, e.g., tar uvf myfile.tar *.log to add all log files to existing tar file myfile.tar. Use compress myfile.tar to replace myfile.tar with a smaller compressed version call myfile.tar.Z.

  14. Working with 2 windows in emacs. You can split the emacs screen into 2 windows to work on different parts of the same file, different files, or to have an S-within-emacs session in one window with a text (e.g. source and/or output) file in the other window.

    To open a second window, type Ctrl-x 2; type Ctrl-x o or use the mouse to switch to the other window; type Ctrl-x 1 to revert to a single window. When you first open a second window it shows the same file as the first window; to put another, already-opened file in the window, use the Ctrl-Left Mouse Button menu or Ctrl-x f and the name of the file; to put an unopened file into a window, use Ctrl-f and the file name (or Ctrl-r for read-only); to open a new file in a window, use Ctrl-f and a new file name. You can change the relative sizes of the windows: e.g. to make the current window 5 lines bigger (at the expense of the other window) type Ctrl-u 5 Ctrl-x ^.

  15. Working with columns in emacs. You can cut and paste columns (rectangles) in emacs. For instance you could cut out the fourth column of a table and paste it into the second column position. The procedure is: put the cursor in the upper left corner of the rectangle to be cut; mark the corner by using Ctrl-SpaceBar (use Ctrl-g to cancel this if done in error); move to the lower right corner of the rectangle with the arrow keys, Ctrl-e, or by searching with Ctrl-s; cut out the rectangle with Ctrl-x r k (not Ctrl-x Ctrl-r Ctrl-k); if the cut is incorrect use undo (Ctrl-Shift-Underscore) to undo it; if you want to paste the cut material, in column form, in one or more places, put the cursor at the upper left of the paste position and type Ctrl-x r y.

  16. screen snap shots: You can make screen snaps from xv. Right click to get the xv menu. Choose "Grab". This works best if you have automatic window raising set in which case, don't bother with the "delay". Instead just click "Grab", "float" the window you want on top, and either left click to get the whole window or middle click and drag to get a region.

  17. Want to connect to Andrew? From your statistics account, you can make your andrew files available by typing klog your-Andrew-userid and then supplying your Andrew password. Now your Andrew files are available for listing, editing, etc. via the file path "\afs\andrew\usr\~your-Andrew-userid". E.g. ls \afs\andrew\usr\~billyjoe lists files in your Andrew area.
    Alternately you can type telnet unix.andrew.cmu.edu then enter your Andrew userid and password. Now you are actually running programs on Andrew. When you want to exit your Andrew account, use logout.
    To actually run programs on Andrew, e.g. the version of Splus to which undergrads have access, using X-windows, do the following. First klog to make the file system accessible. Then run xhost + unixnn.andrew.cmu.edu where nn is the number of a particular Andrew machine. (You can do a quick login/logout via telnet to identify such a machine.) Then do slogin unixnn.andrew.cmu.edu. Now you are on the Andrew machine, and you can run any X-windows stuff, e.g. graphs in Splus, and they show up on your computer.

  18. How can I make my computer beep when mail arrives? Just run xbiff. Even if it is minimized, it will beep when mail arrives.

  19. Want to forward your Andrew mail to your Statistics account? Telnet to andrew (see previous tip). Type forward userid@stat.cmu.edu to send all Andrew mail to userid on the statistics department computer network. Type forward -r to see what your current forwarding is. Type forward -z to cancel forwarding.

    Or try CMU Email and Calendar.

  20. To setup your mail for a vacation message start in your root (top) directory and 1) make a text file named .vacation.msg with the message that you want people to see, and 2) make a file called .forward with the line \myid, | "vacation myid". Replace myid with your username and include the backslash, vertical bar (pipe) and quotes. Also, don't add extra spaces. Anyone e-mailing you will get your vacation message as an automatic reply. (Delete .forward when you return.)

  21. How do I use the optical jukeboxes? Instructions are now at CMU Stat Computing .

  22. How do I make my own graph paper? Use lines with a command string like lines 2 3 >2x3.ps to make a postscript printable file with horizontal lines 1/2 cm apart and vertical lines 1/3 cm apart (2x3.ps). Or use this 1x1 cm paper.

  23. Use the soffice program to view Microsoft Word .doc files in Unix.

  24. Use the looktex program to search for a word or phrase in all .tex documents in the current directory.

  25. Here is a sample csh shell script called cshlooping that operates on a fixed width sequence of numbered file names. Test it with source cshlooping 4 to get results
         easy way (count)
         File001.dat
         File002.dat
         File003.dat
         File004.dat
         
         robust way (arrays)
         File001.dat
         File002.dat
         File003.dat
         File004.dat
         
  • For remote Access to Andrew account from Stat account, use:
    klog (access andrew accounts from elsewhere)
    # If you don't know your usr#, use "pwd" after logging in.
    # Now read/copy files:
    ls /afs/andrew.cmu.edu/usr19/logInName
    
    # Actual remote connection (e.g., to run SAS)
    ssh unix.andrew.cmu.edu
    # Find current IP address:
    /sbin/ifconfig  (Shows "inet addr")
    # Need to set Xconfig for X-Win32 "Allowed Host Addresses" to the inet addr
    #   if, e.g., emacs, gives "Display ... unavailable" message.
    # Need to set unix display for x-window services
    setenv DISPLAY myName.stat.cmu.edu:0.0
    # Now you can use emacs, SAS, etc.
    # (Use cp /afs/andrew.cmu.edu/usr19/logInName/myFiles . in a Stat window
    #   to copy your work back to your stat account.)
    


    Good Unix Links


    All links active 2/28/2006. Please report missing links to


    Up To my Home Page