FAQs for UNIX/Linux

 
  1. Q: How do I change my password?
    A1: "mathpasswd" (to change all your UCSD Math passwords)
    A2: Use the Change Password webapp.
    A3: To change your UCSD Math passwords individually: "passwd" to change your Unix login password, and "smbpasswd" to change your Samba SMB password. You should also change your UCSD Active Directory (AD) Password too.
  2. Q: How do I forward my "username@math.ucsd.edu" email to a new email address?
    A1: At the root of your home directory, use your favorite Unix text editor and create a file named ".forward" containing the new email address on a single line.
    A2: If you're not familiar with how to use a Unix text editor (e.g. vi, emacs, pico, etc.) to create this ".forward" file, here is a simpler method:
    1) SSH remote login to your Math Account on the server euclid.ucsd.edu.
    2) At the Unix prompt, type the following command (don't forget to substitute in YOUR new email address for the example "username@somewhere.com" part):

    echo "username@somewhere.com" > $HOME/.forward

    3) Now send a test message to your username@math.ucsd.edu address and see if it is automatically forwarded to your new email address. No copy will be saved in your Math Account.
    4) If you ever need to cancel this mail forwarding in the future, just delete the ".forward" file by using the command "rm $HOME/.forward". If you ever need to change the new email address to a different one, just delete the .forward file and repeat the above steps again with the newer email address.
    5) NOTE: If you want to both forward email AND leave a copy of the email in your Math Account, then the .forward file should instead contain "\username, username@somewhere.com" on a single line (the first "\username" part is YOUR Math Account username and the second "username@somewhere.com" part is your new email address).
  3. Q: How do I change my default login shell? The "chsh" command doesn't work.
    A: "passwd -r nis -e". The list of valid shells is listed in /etc/shells which you can view by typing "cat /etc/shells".
  4. Q: How do I change my finger name/GECOS information? The "chfn" command doesn't work.
    A: "passwd -r nis -g".
  5. Q: How do I print PostScript .ps files that are pre-formatted in European/ISO "A4" 8.26x11.7-inch paper size onto standard "US Letter" 8.5x11-inch size paper?
    A1: "mpage -1 -o -bLetter mya4file.ps | lpr -Pp7132"
    A2: "psresize -PA4 -pletter mya4file.ps | lpr -Pp7132"
    A3: Some PostScript viewer programs let you specify an output scaling factor when printing. Try a scale of "94%" or smaller.
    A4: If all else fails, mathhelp stocks a LIMITED supply of A4 paper that can be used to manual feed a printer. Please contact us for assistance.
  6. Q: How do I print double-sided (duplex) on a duplex-capable printer?
    A: Print to the double-sided (duplex) queue name of the printer. This is the name of the printer and the letters "_d" (underscore "d") appended to it (e.g. "p7132_d" is the double-sided (duplex) queue for the "p7132" printer).
    A1: "lpr -Pp7132_d myfile.ps"
    A2: "lp -d p7132 -o duplex myfile.ps"
  7. Q: How do I create a PDF file from a LaTeX/TeX file?
    A: For example, suppose you have a LaTeX document named "myfile.tex", the recommended sequence of commands to create PDF files for either web viewing/download use or for submission to NSF FastLane is:

    1) "latex myfile.tex"
    2) "xdvi myfile.dvi &"
    3) "dvips -P pdf -G0 -o myfile.ps myfile.dvi"
    4) "ghostview myfile.ps &"
    OR
    4) "gv myfile.ps &"
    5) "distill -compatlevel 3.0 -embedallfonts on -subsetfonts on -maxsubsetpct 100 myfile.ps"
    OR
    5) "ps2pdf -dMaxSubsetPct=100 -dCompatibilityLevel=1.2 -dSubsetFonts=true -dEmbedAllFonts=true myfile.ps"
    6) "acroread myfile.pdf &"
    You can skip steps #2 and #4 if viewing the intermediate .dvi and .ps files is not needed. Steps #3 and #5 are the really critical ones in order to get the proper results.
  8. Q: How do you print a .pdf file?
    A1: Launch Acobrat Reader using "acroread" on a Xwindows-capable terminal and then do a File menu -> Open... of the file you want, then go to File menu -> Print...
    A2: If you want to stick to the command line only:
    "acroread -toPostScript myfile.pdf; lpr -Pp7132 myfile.ps"
    OR
    "pdf2ps myfile.pdf; lpr -Pp7132 myfile.ps"
  9. Q: How do you rename a file?
    A1: "mv oldfile.txt newfile.txt" (think of it as MoVing from one filename to another).
  10. Q: How do you delete a directory containing many subdirectories/files?
    A1: "rm -rf mydirectory" (be careful when using this command!).
  11. Q: I tried to use "rm -f myfile.txt" to forcibly delete a file but it still asks me to confirm the deletion.
    A1: That's because the "rm" command is aliased to "rm -i" (interactively confirm deletions) in the global shell startup scripts, for safety reasons. To temporarily bypass this alias expansion for the current instance, you can either prefix a "\" backslash in front of the "rm" (e.g. "\rm -f myfile.txt") or you can specify the full pathname for rm (e.g. "/bin/rm -f myfile.txt"). If you trust yourself to always use the "rm" command wisely and don't want it to ever confirm deletions, you can unalias the "rm" command in your startup scripts by putting in a line "unalias rm" at the end of your .cshrc file. If you do this, please remember that there is no such thing as a real "undelete" in Unix. Once a file is deleted, it is basically gone forever.
  12. Q: How do you delete a file/directory with spaces in it?
    A1: Use " double quotes around the file/directory name (e.g. "rm "dir with spaces"").
    A2: Use \ backslashes before each space (e.g. "rm dir\ with\ spaces")
    A3: For tcsh/bash, use the filename completion feature by typing the first couple letters of the file/directory name, then hit Tab, the next couple of letters, and so on until you have the complete name.
    A4: Use "rm -i file*" (first couple letters of file/dir name, immediately followed by the * asterisk symbol). This will ask you to confirm what files to delete. Be careful though!
  13. Q: Ooops! I accidentally deleted a file or some of my email messages. How do I get it back?
    A1: You can't. Too bad. Unix doesn't really have a real "undelete" command. Be more careful next time.
    A2: If you absolutely insist, please contact mathhelp@ucsd.edu and we'll attempt to recover it for you from the system backups. No guarantees. Depending on exactly what file you deleted, where it was originally stored, and exactly when it was deleted, it may be very easy to recover or it may be impossible. If you decide this is your best course, please notify us ASAP. The longer you wait, the harder it is to try and recover.
  14. Q: I tried to download and print an Adobe Acrobat PDF (Portable Document Format) file from the web but the printer status light flashes for a little while and only the banner page comes out but not the document. The computer also reports that there was some sort of PostScript error about "OffendingCommand: blah blah blah".
    A1: Powercycle reset the printer and try printing the PDF file again. That means turn the printer completely off using the printer's power switch/button. Wait 10 seconds. Then turn it back on. This is because there is some sort of weird firmware bug with the newer-model HP printers that cause it to fail to print PDF files after certain other files have been sent to it beforehand. We suspect that the PostScript Level 2 emulator code used on newer-model HP printers has trouble dealing with certain newer Adobe PostScript commands (apparently, the emulation is not good enough).
    A2: If that still doesn't work, this means the printer aborted printing the .pdf file because it didn't understand the PostScript code that had been generated for it from Adobe Acrobat. It seems there's a number of .pdf files on the web that aren't created correctly for some reason. What sometimes works is to convert the original .pdf file into a .ps PostScript file and then re-make a new .pdf file:
    1) "acroread -toPostScript origfile.pdf"
    2) "mv origfile.ps newfile.ps"
    3) "distill -compatlevel 3.0 -embedallfonts on -subsetfonts on -maxsubsetpct 100 newfile.ps"
    4) "acroread newfile.pdf &"
  15. Q: How do you use the Unix "procmail" command to filter my incoming email?
    1) "vi $HOME/.procmailrc"
    2) (EXAMPLE .procmailrc -- NOTE: The "#" hash mark indicates a commented out line):
    ###
    ### .procmailrc
    ###
    
    ### Set the correct shell and $PATH
    SHELL=/bin/sh
    PATH=/bin:/usr/bin:/usr/local/bin
    
    ### Default directory to save mailboxes for filtered messages
    #MAILDIR=$HOME          ### For mail/mailx
    #MAILDIR=$HOME/Mail     ### For elm/mutt/dtmail/mailtool
    MAILDIR=$HOME/mail     ### For pine/IMAP
    
    ### Enable extended logging
    LOGFILE=$HOME/.procmail.log
    #VERBOSE=yes
    VERBOSE=no
    LOGABSTRACT=all
    #LOGABSTRACT=no
    
    
    ### Filter SPAM using campus SpamAssassin into "spam" mailbox
    :0:
    * ^X-Spam-Level: \*\*\*\*\*
    spam
    
    ### Delete all SPAM mail
    #:0
    #* ^X-Spam-Flag: YES
    #/dev/null
    
    ### Copy all incoming mail to backup before processing
    #:0 c:
    #BACKUP
    
    ### Filter by Subject: header
    #:0:
    #* ^Subject.*mysubject
    #othermailbox
    
    ### Filter by From: header
    #:0:
    #* ^From.*username
    #othermailbox
    
    ### Filter by To: header
    #:0:
    #* ^To.*username
    #othermailbox
    
    ### Filter by To: header using procmail's "^TO" regular expression
    #:0:
    #* ^TOusername
    #othermailbox
    
    ### Filter message bodies containing "searchstring"
    #:0 B:
    #* searchstring
    #othermailbox
    
    ### Filter postmaster or MAILER-DAEMON error messages
    #:0:
    #* ^FROM_MAILER
    #postmaster
    
    ### Filter a specific email address into "from_username" mailbox
    #:0:
    #* ^From.*username@math\.ucsd\.edu
    #from_username
    
    ### Filter "all-at-ucsd" campus announcements into "all-at-ucsd" mailbox
    #:0:
    #* ^From.*all\-at\-ucsd
    #all-at-ucsd
    
    ### Filter "ucsd-notices" campus announcements into "ucsd-notices" mailbox
    #:0:
    #* ^From.*ucsd\-notices
    #ucsd-notices
    
    ### Filter "ucsd-flyers" campus announcements into "ucsd-flyers" mailbox
    #:0:
    #* ^From.*ucsd\-flyers
    #ucsd-flyers
    
    ### Filter all campus announcements (see "http://adminrecords.ucsd.edu/Notices/maillists.html")
    #:0:
    #* ^From.*(adminrec|all\-at\-ucsd|ucsd\-notices|ucsd\-flyers|all\-official\-l|all\-staff\-at\-ucsd|all\-academic|academic\-flyers|all\-students\-at\-ucsd|all\-public\-students\-at\-ucsd|all\-undergrads\-at\-ucsd|all\-gradspros\-at\-ucsd|student\-flyers)
    #ucsd-announcements
    
    ### Filter "Subject:" headers containing "seminars" into "seminarslist" mailbox
    #:0:
    #* ^Subject.*seminars
    #seminarslist
    
    ### Filter based on 2 "and" conditions ("From:" contains "nsf.gov" AND "Subject:" contains "grant")
    #:0:
    #* ^From.*nsf\.gov
    #* ^Subject.*grant
    #nsfgrants
    
    ### Forward a copy of all email to elsewhere
    #:0 c
    #! username@elsewhere.com
    
    ### Forward all email to elsewhere
    #:0
    #! username@elsewhere.com
    

    3) For manual, on-demand filtering of the existing old messages in your current INBOX incoming mailbox only, run the command "filterprocmail" as needed. Be aware that if you have large INBOX mailbox, this can take a very long time, so be patient until the command finishes. That's it. Skip the following steps.
    4) To enable automatic, incoming email filtering for all new future emails, "vi $HOME/.forward".
    5) Type the following in ONE LONG SINGLE LINE including the beginning and end " quote marks (for the "username" part, substitute in your actual login username on euclid, NOT the word "username"; also leave the leading "#" hash mark in front of "username" present):

    "|IFS=' ' && p=/usr/local/bin/procmail && test -f $p && exec $p -Yf- || exit 75 #username"

    Save the file. IMPORTANT: Make sure the above is kept to ONE LONG SINGLE LINE (your web browser may automatically wrap it into two lines for display reasons but this entire line in your .forward file MUST be one long contiguous single line with no line breaks in the middle or procmail will NOT work correctly!)
    6) Procmail filtering is now active! Send yourself a test message (preferably from a non-UCSD account if you can). You can check the "$HOME/.procmail.log" file to see what actions were taken.
    More info available via:
    "man procmail", "man procmailex", "man procmailrc",
    http://www.procmail.org/
    http://www.ii.com/internet/robots/procmail/
    http://www.guckes.net/procmail/
    http://porkmail.org/era/procmail/
    http://pm-doc.sourceforge.net/
  16. Q: How do I make a histogram in Microsoft Excel?
    A: In a new Excel workbook sheet, follow the example instructions listed in Microsoft Knowledgebase article Q189519 EXACTLY. Once you understand how to create a matching simple histogram with the example data, then do it again on your own set of real data.
    A2: If you can't find the Tools menu -> Data Analysis... -> Histogram option within Excel, then that means the "Analysis Toolpak" Add-In for Excel was not enabled. To enable them, go to the Tools menu -> Add Ins... -> Check ON both the "Analysis Toolpak" and "Analysis Toolpak - VBA" options -> OK. If there are no "Analysis Toolpak" options listed in the Add-Ins list, then those Add-Ins were not installed when Excel was originally installed. Please contact mathhelp@ucsd.edu to have the Add-Ins installed.
  17. Q: How do I take a screen snapshot or print the screen in XWindows?
    A: "xwd -out myscreen.xwd; (Use crosshair cursor and click on window); xpr -outfile myscreen.ps myscreen.xwd; lpr -Pp5880c myscreen.ps"
  18. Q: How do I get a webpage subdirectory to automatically list all the enclosed items without creating an "index.html" file for it? (This is also known as "auto-indexing" or "Options Indexes" for the Apache web server).
    A: For security and privacy reasons, it is safest to create an "index.html" webpage file containing "<A HREF="myphoto1.jpg">myphoto1</a>" anchor links pointing to the specific enclosed files you want listed.
    This is the best way to guarantee that anonymous web browsers can't randomly navigate through your public_html directory tree for files you did not specifically intend for them to see (e.g. homework solutions intended for public posting at a later date, etc.)
    For certain webpage subdirectories like picture image archives, updating an "index.html" may be inconvenient. To selectively activate the "Options Indexes" automatic directory indexing feature of the Apache web server on a per directory tree basis:

    1) First, make sure the subdirectory has the correct file permissions to allow the listing of enclosed files. Use the command "chmod 755 mysubdirectory" or "chmod og+rx mysubdirectory". The default umask settings for most accounts should have already done this for you automatically. However, it is recommended that your top-level "public_html" webpage directory remain in the more secure setting of "chmod 711 public_html" and only certain subdirectories inside of public_html should be opened up.

    2) Second, create a file named ".htaccess" inside the highest subdirectory level you want this option enabled containing the following line:

    Options +Indexes

    (The "+" sign is important as to how the web server interprets this option. Don't forget it!)

    This will "add" (enable) the automatic "Indexes" feature of the Apache web server for that particular directory tree on down (including all enclosed subdirectories that also do not have their own "index.html" file). Also make sure the ".htaccess" is set to be world-readable using the command "chmod 644 .htaccess". You can have multiple .htaccess files in different directories to control different levels of access.

    By default, long filenames are visually truncated in the directory listings in order to maintain consistent column spacing. To always show the full filename, also add the following option:

    IndexOptions NameWidth=*

    For more detailed info or advanced configuration, see the Apache documentation section on mod_autoindex.
  19. Q: How do I password-protect part of my webpage area?
    A: For example, suppose you want to password-protect the files inside the subdirectory named "mysecretdir" inside your public_html webpage area and only allow the special web user named "mysecretuser" to access it.

    First, create a separate web password file specifically for this "mysecretdir":

    1) "cd $HOME"
    2) "mkdir -p htpasswds"
    3) "chmod 711 htpasswds"
    4) "cd htpasswds"
    5) "touch htpasswd-mysecretdir"
    6) "chmod 644 htpasswd-mysecretdir"
    7) "htpasswd ./htpasswd-mysecretdir mysecretuser"
    8) At htpasswd's "New password:" prompt, type in the new web password you want to use for the "mysecretuser" web account. For security reasons, DO NOT set this web password to the same as your own personal Math Password.

    The above commands create a new subdirectory named "htpasswds" (if it does not already exist) inside your account's home directory, and also a new web password file named "htpasswd-mysecretdir" inside of the "htpasswds" enclosing subdirectory. The "htpasswd-mysecretdir" web password file contains the web account username and the encrypted version of the web account's password in the format "webusername:webpassword".

    Be aware that when using the regular HTTP protocol, this web password will be transmitted in cleartext and can be vulnerable to network sniffing, meaning malicious hackers can potentially capture and steal this web password. This is the main reason why you should not set this web password to be the same as your own personal Math Password. For sensitive info, it is best to use the SSL-encrypted HTTPS protocol instead and advertise a "https://"-type URL link if you wish to to protect against network sniffing.

    If you want to have different web accounts access this same "mysecretdir" area, run the "htpasswd" command again for the different web account username(s) as needed (e.g. "htpasswd htpasswd-mysecretdir user1", "htpasswd htpasswd-mysecretdir user2", etc.). Inside the "htpasswds" subdirectory, you can store additional web passwords files (e.g. "htpasswd-otherdir", etc.) for controlling access to different password-protected web subdirectory areas.

    Second, create and configure a ".htaccess" file in "mysecretdir" to enable password protection using the "Basic Authentication" type:

    1) "cd $HOME"
    2) "cd public_html"
    3) "mkdir mysecretdir"
    4) "chmod 711 mysecretdir"
    5) "cd mysecretdir"
    6) "touch .htaccess"
    7) "chmod 644 .htaccess"
    8) Edit the ".htaccess" file (e.g. "vi .htaccess") and type in the following lines:

           AuthType Basic
           AuthName "MySecret"
           AuthUserFile "/home/MYUSERNAME/htpasswds/htpasswd-mysecretdir"
           Require valid-user

    For the AuthUserFile line, don't forget to change the "MYUSERNAME" part to your own Math Account Username in all lowercase (e.g. "username") so that the file path is correct. You must use the full absolute filepath to the correct htpasswd file for this line. Do not use relative paths or username shell expansion or variables like ~username, $USER, $HOME, etc. for this line.

    On most web browsers, the AuthName setting is what appears as the "Domain:", "Realm:", or window title in the web browser authentication window, so you can change the AuthName setting to something else that you prefer users see. Don't make this line too long as some web browsers truncate this text.

    9) Create a default "index.html" file for this mysecretdir directory and copy whatever other files or subdirectories you want to be inside this password-protected webpage area.
    10) Use a web browser and go to "http://www.math.ucsd.edu/~username/mysecretdir/" (or "https://www.math.ucsd.edu/~username/mysecretdir/" to use SSL). It should ask you for the username and password for the web user "mysecretuser". Be aware that most web browsers will automatically cache and remember the "mysecretuser"'s password after the first successful login, so you may need to completely quit out of the current web browser session and re-launch it to properly test the web password again.

    11) ADDITIONAL NOTES:
    a) To change the web password for "mysecretuser", change directory to "$HOME/htpasswds" and run the "htpasswd ./htpasswd-mysecretdir mysecretuser" command again. To delete the "mysecretuser" web account, edit the "htpasswd-mysecretdir" file (e.g. "vi htpasswd-mysecretdir") and delete the entire line containing the "username:password" entry for that particular web account (e.g. "mysecretuser:/.4Wm1AsvgZ1I"). To delete all web accounts, it is faster to just delete the entire web password file (e.g. "rm htpasswd-mysecretdir") and repeat the steps above to re-create it with new web accounts.

    b) If you wish to always enforce using SSL when entering the web password, the simplest solution is to add these following lines to the BEGINNING of your .htaccess file (don't forget to change the "~MYUSERNAME" and "mysecretdir" parts to your own info):
      SSLOptions +StrictRequire
      SSLRequireSSL
      SSLRequire %{HTTP_HOST} eq "www.math.ucsd.edu"
      ErrorDocument 403 https://www.math.ucsd.edu/~MYUSERNAME/mysecretdir/
    

    c) If you wish to restrict access to UCSD-only networks, add the following to the .htaccess file:
      Order deny,allow
      Deny from all
      Allow from .ucsd.edu
      Allow from 128.54.0.0/16
      Allow from 132.239.0.0/16
      Allow from 137.110.0.0/16
      Allow from 169.228.0.0/16
      Allow from 172.16.0.0/12
    
    Please note that the UCSD network is rather large with multiple IP subnets but the above should cover the majority of the public IP addresses assigned under the ucsd.edu domain. This includes users connecting via the UCSD VPN service or UCSD webproxy service. A more comprehensive up-to-date UCSD IP address subnet list is available on the IPspace SysWiki webpage (accessible only from UCSD IP addresses).

    For more detailed info or advanced configuration, see the Apache documentation section on Authentication, Authorization, and Access Control.
  20. Q: I used emacs -> Read Mail (RMAIL) earlier and it moved all current incoming mail into the file ~/RMAIL and now I can't use any other mailer (e.g. pine, elm, mail, etc.) to read my old mail any more?
    A1: The emacs RMAIL program normally converts your mbox-formatted mailbox into its own BABYL-formatted mailbox. To convert it back, type "formail -B -s < ~/RMAIL >> $MAIL" and avoid using RMAIL ever again.