Assorted linux recipes

Photos.   I unload the SD-card of my Panasonic camera by sticking it into the R600's card reader and using a script as:
 
  #!/bin/csh
  # script:~ unloadpanasonic, thanks to Cees Bassa
  cd /media/*/DCIM
  cp -uprv *PANA ~/photos/panasonic/origs
  foreach dir (*PANA)
    cd $dir
    chmodopen
    chfil JPG jpg
    jhead -n%y%m%d-%H%M%S-%f -autorot  *.jpg
    cd ~/photos/panasonic/origs
  end
  setenv TODAY `date "+20%y-%m-%d"`
  mkdir -p $TODAY
  mv *_PANA/* $TODAY
  rmdir *_PANA
  rm -rf  /media/*/DCIM/\*
where [install:  jhead] is used to redefine photo filenames starting with date-time.  They go into an panasonic/origs subdirectory with the present unload date as name.  I run similar scripts for other cameras so that merging their files puts all photographs in sequential time order (if the camera clocks were synchronous; in group travel one should ask everybody to reset their camera to local time, but if this was not done one can readjust the exif time stamps afterwards with the jhead -ta and jhead -da options).  Script chmodopen resets directory and file protections in the current directory and underneath to read permission for others:
  #!/bin/sh
  # script:~ chmodopen, from Wim Lavrijsen
  chmod 755 .
  find . -maxdepth 10 -type f -exec chmod 644 {} \; 
  find . -maxdepth 10 -type d -exec chmod 755 {} \;
of which the reverse chmodclose has chmod settings 600 and 700.  Script chfil modifies filenames in the current directory by replacing filename parts:
  #!/bin/csh
  # script:~ chfil, by Alfred de Wijn
  foreach file (*$1*)
    mv ${file} `echo ${file} | sed -e "s|$1|$2|g"`
  end
and has a counterpart chfildeep to do so also in underlying directories:
  #!/bin/csh
  # script:~ chfildeep, by Alfred de Wijn
  find . -mxdepth 10 -type f -name "*$1*" | sed -e "s/\(.*\)$1\(.*\)/mv \1$1\2 \1$2\2/" | bash
After manually weeding out bad photos in the origs dir with qiv, I use the following script to produce XVGA (1024x768) versions for spreading and projection in another directory:
  !/bin/csh
  # file:~ panasonicconvertall 
  #       usage:~ panasonicconvertall dir/filenamestart
  foreach file (*.jpg)
    setenv FILETAIL `echo $file | sed -e "s|.jpg||"`
    convert -linear-stretch 0.1%x0.1% -sharpen 2.0x2.0 -geometry x768 -quality 90 $file ${1}${FILETAIL}-NS.jpg
  end
ImageMagick used by convert has lots of worthwhile commands, e.g., convert -sigmoidal-contrast which emulates the nonlinear growth-curve response of photographic emulsions that made my Kodachrome slides span large contrasts much better than digital projection does.  For example, convert -sigmoidal-contrast 3,0% brightens too dark objects.

I then use [Install:  album] from http://marginalhacks.com/Hacks/album to generate clicker albums like my travel albums and the DOT solar image album and the DOT photograph album with:
    album -clean -index album.html -no_image_pages -no_embed -geometry 300x300 -no_crop -columns 3 .
generating captions with a file captions.txt.

Movies.   [Install:  mplayer] gives you the best movie player around.  I made applications such as acroread use mplayer by going to Places > Home folder, <find a .mov or .mpg>, right-click > properties > open with > add > use a custom command > specify loopmplayer, check the bullet.  Movies then open full-screen and repeat until you quit with q.  The script loopmplayer gives infinite looping that becomes seamless by putting -loop 0 after the file specification:

#!/bin/csh
# script:~ loopmplayer = play movie full-screen looping
mplayer -fs $1 -loop 0
I call movies in pdflatex with (for example):
  \def\movie{/home/USER/PATH-TO-MOVIE}
  \def\figs{/home/USER/PATH-TO-FIGS}
  \href{run:\movie/movie.mov}
       {\epsfig{file=\figs/movie-snap.jpg,width=180mm}}}
where I obtain the clickable image movie-snap.jpg as a snap from album.  I also use album to add .avi and .mov versions of solar .mpg movies made with IDL from DOT image sequences to the DOT movie album at http://www.staff.science.uu.nl/~rutte101/dot/albums/movies/album.html with:
  #!/bin/csh
  # script:~ dotmovie2album = convert .mpg movie into .avi and .mov
  # params:~ $1 = desired fps (f.s) playing rate, $2 = filename.mpg
  ffmpeg  -sameq  -i $2  $2:gr.avi
  avifix  -f $1,1  -i $2:gr.avi
  ffmpeg -sameq  -i $2:gr.avi  $2:gr.mov
  mv $2:gr.avi ../dot-albums/movies
  mv $2:gr.mov ../dot-albums/movies
  cd ../dot-albums/movies
  album -clean -index album.html -no_embed -geometry 400x400 -no_crop -columns 2 .
needing [install:  ffmpeg] and [install:  transcode] which contains avifix.  They may need non-free codecs from the medibuntu repository:
  sudo echo "deb http://packages.medibuntu.org/ jaunty free non-free"  >> /etc/apt/sources.list
  sudo apt-get update && sudo apt-get install medibuntu-keyring && sudo apt-get update
  sudo apt-get install non-free-codecs
The .mov versions play even in the simplest QuickTime players.

Grep manual.   I often use a special alias rr meaning "Rob-asks-Rob-a-question": 
   alias rr 'grep \!^ ~/manuals/rrmanual.txt'
which answers my questions "rr some-term" such as "rr chmod".  File rrmanual.txt has many one-liner linux reminders to myself, including:

  colors Ubuntu   em /usr/share/texmf-texlive/tex/latex/graphics/dvipsnam.def
  xfontsel &                select a font
  xlsfonts > fonts.fil      write all font names to file
  chmod 644 file       -rw-  r--  r--    others may read (umask 022 default))
  chmod 600 file       -rw-  ---  ---    others may not read file
  chmod 755 dir        drwx  r-x  r-x    others may enter (umask 022 default)
  chmod 755 script     drwx  r-x  r-x    others may execute 
  chmod 700 dir        drwx  ---  ---    others may not enter dir
  chmod 744 script     drwx  r--  r--    others may read; I may execute  
  chmod 444 file       -r--  r--  r--    even I may read only, protection
  chmod 711 dir        drwx  --x  --x    others may enter but not list dir
  chmod root.root file                   reset to owner/group both root  
  cp -uprv dirname dir > cp dirnamedir.txt    copy update all, with log file
  convert -density 300 -quality 80 -crop 0x0 -geometry x768 file.ps file.jpg
  convert 'vid:*.jpg' directory.miff     make thumbnail index album 
  display directory.miff &               show thumbnail index album 
  gqview                                 image browser, slide show
  qiv -fim *jpg                          fast image viewer, d=delete to subdir
  qiv -fis -d 1.5 *jpg                   fullscreen slide show 1.5s cadence
  feh                                    fast image viewer 
  eog                                    eye-of-gnome image viewer
  jpeg2ps -h fig.jpg > fig.eps           good image converter
  ps2pdf -dPDFsettings=/prepress file.ps file.pdf          like acrodist
  psnup -2 file.ps > file2.ps            2A4-on-one pdf talk printout 
  ps  612 792 <-> 595 842 (pt)           hack ps to convert USA B4 <-> A4   
  ps x | grep processname                list all processes called processname
  ifconfig                      check ethernet 
  iwconfig                      check wireless 
  recode ibmpc:latin1 file      decode windows file to unix
  xset s off                    screensaver off
  screen (in remote terminal) = start window for remote processing
    CNTRL-a        screen commando
    CNTRL-a c      screen new terminal
    CNTRL-a space  screen cycle terminal
    CNTRL-a d      screen detach terminal (then log out of remote)
    screen -r      screen recover detached terminal (after remote login)
  renice +18 pid   put pid job in batch, sort of (eg when using screen)
  tar cvf *17Jul96.???           tar with joker/wildcard:~ xx.100-999
  tar hcvf dir.tar dir           tar dir with all under, also linked files
  tar xvf files.tar              extract files into directory structure 
  tar tf files.tar               list files only
  wget -r http://etc             get everyting below and above this URL
  wget -r -l 1 -nd http://etc    get everything in this URL dir only  
  lftp ftp://... or lftp http://...    better than wget
  lftp mget -d *                       get all subdirs and files
  lftp mirror -n .                     get update with newer files only
  mgdiff file1 file2              linux:~ differences between two files
  diff -y -W170 --suppress-common-lines file1 file2    differences files
  aspell -t --dont-tex-check-comments check file.tex   latex spell checker
  env TZ=UTC date                 give current date and time in UT

Rob Rutten 2012-05-22