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@www.ladysinger.com" 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@www.ladysinger.com 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 近期世界杯比赛时间
     into "all-at-ucsd" mailbox
    #:0:
    #* ^from.*all\-at\-ucsd
    #all-at-ucsd
    
    ### filter "ucsd-notices" campus 近期世界杯比赛时间
     into "ucsd-notices" mailbox
    #:0:
    #* ^from.*ucsd\-notices
    #ucsd-notices
    
    ### filter "ucsd-flyers" campus 近期世界杯比赛时间
     into "ucsd-flyers" mailbox
    #:0:
    #* ^from.*ucsd\-flyers
    #ucsd-flyers
    
    ### filter all campus 近期世界杯比赛时间
     (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\-2022年亚洲世界杯预选赛
    \-at\-ucsd|all\-public\-2022年亚洲世界杯预选赛
    \-at\-ucsd|all\-undergrads\-at\-ucsd|all\-gradspros\-at\-ucsd|student\-flyers)
    #ucsd-近期世界杯比赛时间
    
    ### 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 "//www.ladysinger.com/~username/mysecretdir/" (or "//www.ladysinger.com/~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.www.ladysinger.com"
      errordocument 403 //www.ladysinger.com/~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.