linux penguin

CS313 Tips and Hints

Printing tips

lpr -Pminir Myfile.java prints the file Myfile.java to the printer minir single-sided
a2ps -2 -Pminir Myfile.java prints the file Myfile.java to the printer minir using a 2 pages/page and double-sided format
lpq -Pminir lists the item in the printer's queue
lprm 349 removes the item -- specified by the job
number -- from the printer's queue (can only be done by the user who placed it in the queue)

Printer names

s160a name of printer in the lab room
sciliba (scilibb, scilibe) science library printer A (and B, and E)
minir (minil) mini focus printer on the right (on the left)
e101 science center printer outside of E101

Linux hints

  1. pwd prints your current working directory , e.g. pwd might produce this: /students/wwellesle/cs313/assignment4
  2. ls -lt lists your files, one per line, with the most recently edited one first.
  3. cat prints the contents of a file to the screen , e.g. cat Myfile.java
  4. more prints the contents of a file to the screen, one screenful at a time. Spacebar moves to the next screen, "q" quits the more, e.g. more Myfile.java
  5. > Output redirection, e.g. java Cyberspace URLlist.txt > tmp
  6. head Shows 1st 10 lines of a file [e.g. head jobs.txt]
  7. tail Shows last 10 lines of a file [e.g. tail jobs.txt]
  8. wget [e.g. wget image.jpg]
    Let's say you want to grab a picture of Brian from the web. Here's one in this page. The path for this image (which you can glean from viewing the source code) is: http://cs.wellesley.edu/~btjaden/pictures/tjaden.jpg
    Try this in linux (all on one line):
    wget http://cs.wellesley.edu/~btjaden/pictures/tjaden.jpg
    and then type "ls" to see what files you now have (and think carefully about the pictures you post online).
  9. C-r (Control r) [linux] allows you to search back through the linux commands that you have typed (similar to yanking with the up arrow key, but can search through your history).
  10. cmp fileA.java fileB.java [linux] Shows the first line number where the two files differ.
  11. diff fileA.java fileB.java [linux] Displays the lines that differ between two files.
    Here are some simple examples using diff.
  12. M-x calendar Displays a calendar (C-x < or C-x > to scroll)
  13. find Finds files or directories (and more).
    • find . -name 'SequenceOps.java' searches all subdirectories of the current (.) directory.
    • find . -name '*.java' lists all .java files in the current directory and subdirectories.
    • find ~ -daystart -type f -atime 1 lists all files that were accessed yesterday
    • man find for more information about find
  14. spell filename.txt lists misspelled words in filename.txt
  15. who Lists other users logged onto your machine.
  16. date Prints the date and time.
  17. cal Prints calendar for given month and year, e.g. cal 10 2008

Emacs hints

  1. Marking for cut and paste using the keyboard
    why? mucho faster than using the mouse. really.
    • Place the cursor at the start of the region that you want to cut
    • Press Ctrl+Spacebar (at the same time)
      On Macs, this often brings up the search window. If this happens, use Ctrl+@
    • It should say Mark set in the modeline, as shown here:
    • Move your cursor to the end of the desired cut area
    • Ctrl-W kills the area
    • To paste it back in, move your cursor to the place where you'd like to insert
    • Ctrl-Y will yank the killed text back (as many times, and in as many places as you'd like: each Ctrl-Y inserts another version of your cut text -- note that you can yank the code into different documents too)
  2. Just a reminder: you can customize your .emacs file in your home directory. Here is a code snippet of my .emacs
  3. To see the list of your color choices, do ESC (let go) X and then type "list-colors-display" (without quotation marks) and hit return.
  4. To change the color of strings in emacs, add this line to your .emacs (remember that your .emacs lives in your home directory):
    (set-face-foreground 'font-lock-string-face "steel blue")
    To see the list of colors, M-x list-colors-display.
  5. ESC (let go) Q reformats text in your file, getting rid of those pesky wrapped lines
  6. Ctrl-s Searches in your file. Type Ctrl-s and then type the string (or fragment of a string that you are looking for). You can repeatedly hit Ctrl-s to find the next occurrence of the string in your document. The search will wrap back up to the top of the document as well.
  7. M-x query-replace [emacs] This is like replace-string except that Emacs asks you whether or not it's ok to replace each occurrence. Useful because sometimes you want to do a nearly global replace, and this is exactly the right command.
  8. C-x 2 Splits window horizontally
  9. C-x 3 Splits window vertically
  10. C-x o (oh, not zero) Switch between windows
  11. C-x f Find the file for your newly opened window
  12. C-x 1 (one) Revert to a single window
  13. Adding a prefix to each line (e.g. //)
    1. C+space to mark the first line
    2. Move cursor to the beginning of the last line
    3. M-x string-rectangle and then type what you'd like to insert
  14. Delete the first few n chars of every line
    1. C+space to mark the first line
    2. Move the cursor to the last line, and move it right n chars
    3. M-x kill-rectangle and then those chars will evaporate from each line
  15. M-x ispell-buffer allows you to step through each misspelled word in your file and offers substitute words.