Friday, November 15, 2013

Handy bash and vim tips that I've used from time to time

BASH
1. Copying files while retaining their directory structure
find ~dir1/ -name "*.mat" | xargs -I{} cp {} ~/<destination>
The directory structure below ~dir1/ where the *.mat files are found are copied to <destination> retaining the structure
2. Scp-ing only a set of files from multiple directories (using find and then scp-ing those files out retaining directory structure
find -name "*.mat" -print0 | tar --null --no-recursion -czf archive.tar.gz --files-from -




VIM
1. To comment or uncomment a block of code
ctrl+v --> select your block of code --> :norm I# (inserts a # in front of each line) or :norm ^x (removes the first character from each line in the selected block)

Thursday, October 31, 2013

Installing java on your linux machine without removing the native version it comes with

I like to have all my software installations in a single place so I know exactly what state my machine is in by glancing at a single directory, say ~/Software
My ancient CentOs setup doesn't have jdk 1.7 in its repo, so instead of fooling around with alternatives <shudder>, I downloaded the jdk version I wanted and put it into said ~/Software directory.

Here's a simple way to go about changing the default version of java that your system picks up without having to uninstall the native java that it comes with.

1. Switch to su
2. Create a file,say java.sh in /etc/profile.d/ containing :

#!/bin/bash
         
JAVA_HOME=/home/ShankarV/Software/jdk1.7.0_40/
                     
PATH=$PATH:$JAVA_HOME/bin:
                                     
export PATH JAVA_HOME

3. Save out the file, and logout and log back in to your machine.
4. To test out your java version, run
java -version
5. To see which executable will be picked up, run
which java

Wednesday, September 25, 2013

Installing 32 bit java on my 64 bit CentOs6 machine

This is a right old pain to do, so unless you really need to, I would say find a way to stick to the native 64 bit jre/jdk install.
As of this writing, the latest jdk version available is 1.7.0_40

A quick listing of the steps I followed are below. The commands are italicised.

1. yum erase jdk (to remove the existing 64 bit java devel environment)

2. Download the x86 version of jdk (the rpm), say jdk-7u40-linux-i586.rpm

3. yum provides  libgcc_s.so.1
    yum install libgcc-4.4.7-3.el6.i686 
(which is what came up as the reqd package from the command above)

4. yum install jdk-7u40-linux-i586.rpm

5. Check your installation with the usual 
    java -version

In case you want both the 64 and 32 bit versions of java installed, you'll have to muck about with alternatives, which I happily chose to avoid!

Wednesday, July 3, 2013

Handy git tricks

Using Git is a blessing, truly it is. Today is just one of those days when I feel like chopping a limb off because git can't understand what I want it to do.
"Restore a file I deleted from my ide, then revert it to its state when I added that line in, then checkout a single file blah blah jabber jabber"

Each time I discover a neat trick to do what I want in git, I shall henceforth make a note of it here :)

  1. Restore a file that you deleted by accident in the repo or Undo all the changes in a file but haven't committed yet.
  git checkout HEAD^ <path to file>

This should bring the file back to the state it is in in the remote repo.

  2.  List all the files included in a commit

git log master

find the commit reference from here eg: 7bdf3a80243c7029508357c45bf4b918ce2bab86
 
git show --name-only 7bdf3a80243c7029508357c45bf4b918ce2bab86