Posts

Showing posts from September, 2015

end of line sequences in different OS

end of line sequencesWindows end of line sequence: \r\n Unix end of line sequence: \n Mac end of line sequence: \r

Recovering moved or deleted files in Linux

I was developing one C program which I spend 1 day writing with around  500 lines of code in Ubuntu 12.04 
for compiling in GCC, I used the below command
# gcc server.c -o server.c
instead of giving gcc server.c -o server 
now my whole source code was replaced with the binary file :( :(  , a simple mistake which caused my whole source code got deleted or replaced. I had a habit of pressing for auto completing the file names. 
After searching for some time googling, i got a solution which worked for me and saved my 9 hours of work.
I got the help form this below link http://www.cyberciti.biz/tips/linuxunix-recover-deleted-files.html
repeating what is said there and which i tried and worked for me
in the console with sudo permission sudo grep -a -B[size before] -A[size after] 'filename or unique content' /dev/[your_partition] > file.txt
-i : Ignore case distinctions in both the PATTERN and the input files i.e. match both uppercase and lowercase character. -a : Process a binary …

counting number of lines in c and include files in Linux

After writing source code in Linux, if you want to count the number of lines in .c and .h files

find . -name '*.c' -o -name '*.h' | xargs wc -l

Converting IP Address from string in dot format to 32 bit integer

C program to convert IPv4 address from String formatted in dat notation like "10.0.0.1" to a 32 bit integer in Linux

#include<stdio.h>
#include <arpa/inet.h>

main()
{

    uint32_t ip;
    struct in_addr ip_addr;

    ip = inet_addr("10.0.0.1");
    printf("IP Integer: %d\n", ip);
    ip_addr.s_addr = ip;
    printf("The IP address is: %s\n", inet_ntoa(ip_addr));

}

Cassandra cqlsh queries

Below are the commands useful for querying the cassandra database .
These are executed by logging into the Cassandra command line interface(CLI), CQLSH

1) showing the keyspaces(or databases )

describe keyspaces;

2)
Showing Tables in the keyspace(or database)

2.1. use <keyspace_name>;

2.2 describe tables;  this will show the tables in the keyspace(database)

3) Creating Index to an Exiting table with column

 CREATE INDEX tripid_idx ON table_4(tripid);


4) To show TABLE info using cqlsh
        DESC TABLE table_1 ;