Posts

Shell commands in VIM

If we need to execute a shell command on currently opened file in VIM, we can do following   :%! sed G          Double space the entire file.   :1,5! sed G        Double space the lines from 1-5.

Downloading flash videos in ubuntu

Here is a modified version of a online script I found to download videos. Online script download everything which is a clutter because it has many flash ads too. $ cat ~/Dropbox/new_installation/scripts/flash_vid.sh #!/bin/bash num=1; for FILE in $(lsof -n | grep "Flash.*deleted" | awk '{printf "/proc/" $2 "/fd/"; sub(/[a-z]+/,"",$4); print $4}'); do cp $FILE $HOME/Desktop/$num.flv size=$( stat -c %s $HOME/Desktop/$num.flv); if [ $size -gt 5000000 ]; then num=$[$num + 1]; else rm $HOME/Desktop/$num.flv; fi done

CVS important commands

cvs add < filename > cvs commit -m "my comment < filename > cvs update < filename > cvs -j < what version you want cvs to think it has > -j<what version you want cvs to go to > < filename >

linux commandline mail from shell as attachement

There are few ways to do this. Here are some : (cat mailtext; uuencode surfing.jpeg surfing.jpeg) | mail sylvia@home.com uuencode $ATTFILE $ATTFILE | mail -s "$SUBJECT" $MAILTO echo "hi" | mutt -a $ATTFILE -s "$SUBJECT" $MAILTO

mysqldump

Transferring data between two tables/two databases can be achieved by insert into table1 select * deom database2.table2; But they are not on the same host you can use following : $ mysqldump -h host_name -u user_name -p database table_name "--where= date = 20111121" > temp We can use "-t" option which will exclude table creation definition from the output.

Finding latest modified file/directory

Another useful command $ find . -exec stat \{} --printf="%y %n\n" \; | sort -n -r | head -1 $ for i in `ls`; do echo -n $i" "; find $i -exec stat \{} --printf="%y %n\n" \; | sort -n -r | head -1;done

Mysql Tricks

How to get current time select now(); select curdate(); select curtime(); How to get date in standard format select date from table; will give answer as "2011-08-15" But select date+0 from table; will give answer as "20110815" To use group by with a summary. select col from .... group by col with rollup; This will give a summary(addition) in the last row. When performing string operations Shell "*" => mysql "%" Shell "?" => mysql "_" Conditional statements in mysql select (sum(case when shares>0 then shares else - end) from table; Case-sensetive comparison select 'A' like 'a'; 1 select 'A' like binary 'a'; 0 Using variables set @total=0;select (@total := 2+@total) as total from table; Checking table sizes select table_schema "Database name", sum(data_length _ index_length)/1024/1024 "size", sum (data_free)/1024/1024 "Free space ...