Thursday, April 21, 2011

Backup and Restore using rsync

I backup my data onto a second hard disk in my PC, like this:

rsync -av --delete /disk1/my/data /disk2/backup > backup.log 2> backup.err

This creates a folder called data in /disk2/backup and copies the contents of the folder /disk1/my/data to it.

If I rerun this command, it will copy only the changed files/directories from /disk1/my/data into /disk2/backup/data.

Restore is simple; /disk2/backup/data is like a mirror. Just browse and copy back whatever is needed.

Note: Using /disk1/my/data/ (with the trailing slash) instead of /disk1/my/data does not cause the directory data to be created. The contents of data are copied directly into backup.

For a one-time copy to an external hard disk, I did this:

rsync -avW --no-compress --delete --modify-window=2 /path/to/src  /path/to/dst > bakup.log 2> bakup.err


Compression is useful for network transfers but can be skipped for local copying. The 'modify-window' option was required since the destination was on an NTFS drive, and there could be time stamp issues when copying from ext3 to NTFS. The 'W' option (copy whole files) might speed things up since partial file transfer need not be supported.

Thursday, March 31, 2011

Latex Math Tips

Summations
  • If summations become cramped, use \displaystyle before \sum.
  • If summations should be cramped, use \textstyle before \sum.

Numbering lines of equations using align
  • Use align to number all lines; use align* to switch off numbering
  • In align, use \notag before \\ to switch off numbering for a line
  • In align*, use \tag{...} to number (or rather tag) a line
  • Given a numbered/tagged line, use \label{...} before \\ to refer to the line using \ref{...}.
  • Use \allowdisplaybreaks to allow a single equation block to be split over two pages.
Canceling terms in expressions
  • \usepackage{cancel}
  • Four options: \cancel{...}, \bcancel{...}, \xcancel{...}, \cancelto{<val>}{...} (in math mode)
  • Use \usepackage{ulem}, \sout{...} to strike out text.
Others
  • Use \boxed{} to put a box around equations(to highlight them). Note: If you use it within the align environment, it should not contain the `&'; otherwise it will give an error.
  • Use \newcommand{\myfrac}[2]{\ensuremath{\frac{#1}{#2}}} to define new commands (\myfrac) with many (2) arguments, and specify replacement latex code (\ensuremath...), including references to the arguments (#1, #2, ...). The new command can now be used in normal latex code (\myfrac{a}{b}). Aside: \ensuremath{} forces its contents to be interpreted in a math environment.

Wednesday, March 30, 2011

Solving equations in MATLAB

syms a b c x - declare variables
solve('a*x^2 + b*x + c') - solve equation

Thursday, March 24, 2011

Using xargs to redirect to command line arguments

To delete all .bak files in a directory, do
rm *.bak or ls *.bak | xargs rm
Essentially, rm is executed once with the whole of the piped input as argument.

To move the .bak files to another place, do
mv *.bak diffdir or ls *.bak | xargs -I var1 mv var1 diffdir.
Here, mv is executed separately for each file listed by ls. var1 is a placeholder. It is replaced each time by a file, and mv is executed.

To rename the .bak files to .bakup files, do
ls *.bak | xargs -0 -I {} mv {} {}up.
{} is another way of specifying a placeholder. -0 takes care of white space anomalies in the piped input.

Tuesday, March 22, 2011

Friday, March 11, 2011

Vim Tips

  • To beautify code (or pretty print, or auto indent), type ESC gg = SHIFT-G. This means:
    • ESC --> back to mode
    • gg --> go to first line
    • = --> indenting
    • SHIFT G --> to end of file.
(Courtesy snipplr.)
  •  To search and replace starting from the cursor type ESC :.,$s/foo/bar/gc. This means:
    • ESC --> back to mode
    • : --> command mode
    • .,$ --> from current line (.) till (,) end of file ($)
    • s --> substitute (foo with bar)
    • g --> all occurrences in a line
    • c --> confirm before replacing
 (Courtesy wikia.)

Monday, February 28, 2011

Problem with sound recording in Ubuntu 9.04

Configuration:
Ubuntu 9.04, HDA Intel (Alsa Mixer)

Problem:
I am using a headphone with mic. I have plugged in the mic, in the right socket. It seems that I have configured everything in Alsa Mixer right. But still sound recording does not work.

Solution:
Go to Volume Control -> HDA Intel (Alsa Mixer) -> Options -> Input Source (the first one). If it is 'Mic', change to 'Front Mic'. Try recording; it will fail. Now change it back to 'Mic'. Try recording again; it should work now.

[microphone, audio, voice]