Some more linux commands

August 21, 2010

$cat fileName //show the contents of the file

$grep text < fileName //show the lines that contain the word “test” inside the fileName

$grep -l text  *.txt //show all .txt files  with “text” word on those

$rev fileName //reverse the contents of the file

$VARIABLE=VALUE //set values to a variable

$echo $VARIABLE //see the value of the variable

$ export VERIABLE //set environment vatiable

#!/bin/bash //first line to write a script

Subversion using Eclipse and Assembla

April 6, 2010

1. Download Eclipse SVN plugin ( subclipse)

a) Go to Help menu of Eclipse -> Add New Software -> add URL (http://subclipse.tigris.org/update_1.6.x)

2. Create a SVN repository anywhere you want (e.g. your university server, other SVN repository providers like assembla)

Use command Line to create a repository:

svnadmin create --fs-type fsfs MyNewRepository

3. Now share/upload your your Eclipse project to the SVN repository

a) Right Click on the eclipse project -> Team -> Share project -> Use Existing Repository -> Add URL -> use user Name/password for your repository

When uploading to a server that does not allow http rather use ssh, use:

svn+ssh://user@ssh.yourdomain.com/path

//you would need to provide your username along with URL

rather than http://…

//http if that server or free space allows http or web access to the repository

4) Team -> Commit – to upload your changes from local

5) Team -> Update – to upload others’ changes to your local

Process and Thread – Any confusion?

February 11, 2010

1. A process is a program/set of codes in execution (running state)

2. Each program on OS that is running is a process

3. Each process concurrently and separately run with other process

4. Inside each process (a program in execution), if several parts of it need to run concurrently, then each concurrently running parts of a process is called thread or lightweight process

Recovering Grub (Boot loader) after installing Windows

January 22, 2010

1. Insert the Ubuntu CD and select “Install without changing current file systems” //this will open the Live CD boot

2. Run “Terminal” from Applications -> Accessories -> Terminal

3. $ sudo grub

4. grub> find /boot/grub/stage1 // it will return (hd? , ?)

5. root (hd0, 4) //previous command at step 4, returned (hd0,4) , and make sure you typed a “space” after root

6. setup (hd0) // again make sure to put a space after setup.

//This will recover the grub

Some shell commands/Scripts

January 21, 2010

1. echo $((2>3)) //expressions

2. test 2 > 3 && echo “Yes” //condition check

3. read -p “Prompt” $variable1 $variable2 //reading from console

4. echo “today is $(date)”

5. var=10 //declaring variable, no space before or after =

6. declare -r y=10 //creating constant or read only variable

7. unset var //frees the variable

8. declare -i y=10 //creating int variable

9. find $HOME -name *.c //finding all c files inside home

10. printf “%s\n” “$varName” //prints

11. sleep 3 //sleeps for 3 sec

12. if condition //if condition

then

command1

command2

..

commandN

fi

13. if condition //if-else condition

then

command1

else

command2

fi

14.

if condition //if-else-if condition

then  command1

elif condition2

command2

elif condition3

command3

else

fi

15. Logical AND, && // Run second command only if first is successful.

16. Logical OR, || // Run second command only if first is successful.

17. grep text file.ext //search text inside a file

18. [ condition ] //condition checking similar to test

19. case $variable-name in

pattern1)

command1

commandN

;;

pattern2)

command1

;;

esac

20.

for var in item1 item2 … itemN

do

command1

command2

commandN

done

2. //declaring function

die()

{

echo “An error occurred.”

}

>die //call it

Reference : http://bash.cyberciti.biz/guide/Shebang    *click the right top arrows to move forward pages

Haskell in Ubuntu 9.10

January 18, 2010

$ sudo apt-get install ghc6  //install

$ ghci //run Haskell

Prelude> putStrLn “Hello World”

Prelude> Hello World //printing into standard output

……………………..

Prelude> :quit //quit from Haskell compiler+interpreter

///////////////////////////////////

creating a Haskell file, compile , run (load)

$ vi File.hs //create haskell file with .hs extension

$ ghci //start Haskell

Prelude> :load File.hs

*Main> File 10 // running File with argument = 10

……… another way from shell without running ghci first …

//compile and generate executable output file named outFile,

//assumed File.hs is already been created with a “main”

$ ghc -o outFile File.hs

$ ./outFile // run the executable

//use  Tab for auto complete option for commands

Encrypt+Decrypt Unix Files

January 16, 2010

Use ccrypt

Install

>> sudo apt-get install ccrypt

Encrypt, command and provide key twice

>> ccrypt -e File

Decrypt, command and provide key once

>> ccrypt -e File.cpt

How to set up wireless network for Ubuntu 9.10?

January 12, 2010

>> sudo apt-get install wicd

//will remove default Network Manger that works only for wired connections and sets up wicd for both wired and wireless

Run jar files on Linux

January 11, 2010

>> java -jar file.jar

Compiling and running simple c++ in linux

January 9, 2010

Edit

>>vi or gedit file.cpp

Compile

>> g++ file.cpp -o out

Run

>> ./out

or

>> ./out inp.in  //providing command line input


Follow

Get every new post delivered to your Inbox.