Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Friday, February 3, 2012

Multiple Comparison in Bash

Checking multiple conditions in Bash can be tricky.

Following require STRING1 and STRING2 to be not empty and COUNTER < MAX.
if [[ -n "$STRING1" && -n "$STRING2" && $COUNTER -lt $MAX ]];
then
...
fi


This post is a nice concise resource.

"knitr" and "ggplot2" for Automatic LaTeX Report Generation with R

knitr is supported under R versions >2.14.1. So I upgraded R, and also needed some extra packages for ggplot2. (probably not all are required for ggplot2 but I am interested in using these packages in my research)

sudo apt-get install libX11-dev libglu1-mesa-dev libxml2-dev libgeos-dev libproj-dev libgdal-dev

Some R packages as well

install.packages(c("rgdal","maps","maptools","rgeos"))

Only, then, was I able to install knitr package according to this post.

install.packages("devtools")
library(devtools)
install_github("ggplot2","hadley")

install_github("knitr","yihui")

Package management with "apt"

Useful information can be found here.
  • Search: apt-cache search [package name]
  • Package info: apt-cache show [package name]

Thursday, February 2, 2012

Apply Commands Only to All Files or Directories

Choose "type" to be "d" (directory) or "f" (file).
find . -type "type" -exec chmod 755 {} \; 
find . -type "type" -exec chown owner.group {} \;

More generally, any "command" will work, too.
find . -type "type" -exec "command" {} \;

Wednesday, February 1, 2012

Running Commands in a Sub-shell

Content is from this post

Here is how to run "/bin/script.sh" inside "/workingdir" without changing your current path.
(cd /workingdir; /bin/script.sh)

Here is how to run sequence of commands with checking status after each command by inserting "&&"
(cd /workingdir && /bin/script.sh)

Memory is better managed by using "exec" command.
(cd /workingdir && exec /bin/script.sh)