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

Jul 30, 2012

Jul 23, 2012

Jul 18, 2012

Installing the latest R on Ubuntu

The Ubuntu version and the latest R versions seldom match. Check the version with:

apt-get update
apt-cache policy r-base


The procedure is to get the latest security key for R from the CRAN page. For example, the security key for 2.15 is signed and maintained by: Michael Rutter. The keys don't usually change all that often. But they changed for Ubuntu 12.04.

Import the key into apt-get, update the apt-get sources list and then install R.

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
gpg -a --export E084DAB9 | sudo apt-key add -
sudo geany /etc/apt/sources.list


In geany, add

deb http://cran.cnr.berkeley.edu/bin/linux/ubuntu/ precise/


At the terminal:

sudo apt-get update
sudo apt-get install r-base r-base-dev

May 13, 2012

Linux and Android sitting in a three...

Three Point Three Point Three Three Three

First came the fork
Then came the merge
Then cometh android
And a basket of apps.




I saw "Kernel" in the Illustration Friday topic and all I could think of was, "Ooh at last, Android and Linux are getting back together in Kernel 3.3!" :-)

Mar 6, 2012

PDF Tools on Linux

Academic lives revolve around PDFs. But it's so tough to find good tools for PDFs on Linux, preferably with a GUI. I keep stumbling on the same old programs that don't work. The idea here is to document programs that did work and those that did not.

PDF Shuffler: did not work. Failed to load a 200+ MB file made of jpg images.

PDFSnip: fork of PDFShuffler. Same problems.

PDF Chain: renamed my pdf, but apart from that wasn't able to do much. Available in the F16 repository and does load PDFs. Could be useful to concatenate pdfs. Has tabs that suggest it can burst them and compress them. Compression does not work.

PDFmod: Did not even boot.

PDFtk: Works really well but this is command line. For rotating individual pages, in a misaligned PDF, it would be awesome to have a visualization tool.

PDFtkforall: Lies. Gui to PDFtk but only for windows users.

PDFmechanic: How does this even work? No instructions. Bleah

jpdftweak: Okay the interface loaded but not a clue how to make this work to rotate individual pages within a PDF!

PDForsell Windows only. 'Nuff said.

So, in short, none of the above worked for me in Fedora 16. Maybe it's time to jump ship to the more pragmatic Ubuntu and abandon the holier-than-though exacerbation of Fedora??

But hang on ...

PDFedit 0.4.5: this one works for rotating individual pages graphically and saving the PDFs. Persistence through bad software has paid off. But has it? Quite inexplicably, the PDFedit package in F16 has been "orphaned" Because the holy Fedora has decided not to support this for F16. There is a workaround (below) to install it. But who knows whether this workaround will make it in the next version of Oooh-I-am-too-bleeding-edge-look-at-me-fedora.

For now, you can install PDFedit on 0.4.5, on F16 by actually installing the F15 version:

yum install pdfedit --releasever=15



Jan 30, 2012

Shell Commands

Some frequently used shell commands

Forcibly remove all the files and subdirectories from a directory and then delete the directory

rm -rf mydir


List only the folders in a directory, not the files

ls -p | grep "/"

OR

ls -d */

OR {list ALL the directories recursively including hidden files}

du

Chopped version (print only the names and not the size before the names):

du|awk '{print $2}'

The most beautiful way of visualizing directory structure

tree -d

Chopped version of the above

tree -d -L 1



List the lines where one column is not equal to another column in the same csv.

awk -F\, '$1 != $4' some.csv



Batch Scripts

Open all similarly named pdf from the folder with evince one by one. One closes and the next opens.

for f in `ls somepatternofname*.pdf`; do echo $f; evince $f; done;


Rename all files in a folder that don't end in pdf to a single extension -".pdf".

for f in `ls * | grep -v pdf`;
do echo $f;
mv $f $f.pdf ;
done;


Rename a particular string to something else

for i in * ;
do j=`echo $i | sed 's#searchstring#replacestring#g' - ` ;
mv "$i" "$j" ;
done


Move all the folders in a particular directory to another directory or folder.

for f in *;
do
echo $f;
mv $f /new/directory ;
done


Rename the extension of multiple files in a folder
Here we are changing foo to bar

for f in *.foo;
do
base=`basename $f .foo`
mv $f $base.bar
done

Dec 6, 2011

Writing a Shell Script


Paired Bash Control Structures

if, while, until, for and case
Paired? Yes, starts and ends with a tag.

-f
checks if it is a regular file

-d
check if the file is a directory

-e
check if the file exists

-f
check if the file is a regular file

-g
check if the file has SGID permissions ???

-r
check if the file is readable

-s
check if the file's size is not 0

-u
check if the file has SUID permissions

-w
check if the file is write-able

-x
check if the file is executable

if [ -f /etc/foo ]; then
If-then control structure.

Finding and listing files with a string of interest in a directory and sub-directories.
find . -type f -exec grep "stringofinterest" {} \; -print


References:
1. Tips for Linux: codecoffee.com