Monday, February 28, 2011

Mercurial HG HOWTO guide

Download: Fast, Fun, Awesome

In this tutorial I will cover the basic commands you will need to use mercurial.
hg help is your first friend and Mercurial Wiki is your second.

Help for Command:
$ hg help <command>
$ hg <command> - -help

Commands to Create, Clone Repository
To make a new repository:
$ hg init <path>

To copy a repository from an existing repository:
$ hg clone <sourcePath>  [<DestinationPath>]

To clone specific branch of the repository:
$ hg clone -r <barnchName> <sourcePath> [<destinationPath>]

To copy existing repository to a new locaiton:
$ hg clone . <newPath>

To get changes from server repository and update working set:
$ hg pull -u

To get changes for specific branch from server repository:
$ hg pull -r <branchName>

To see what changes will come in on a PULL command:
$ hg incoming

To publish changes to specific branch on server repository:
$ hg push -r <branchName>

To see what changes will go out on a PUSH command:
$ hg outgoing

Commands for Add, Remove, Rename, Copy Operation
Add Specific file to repository:
$ hg add <filename1, filename2, ...>

To remove file from repository but don't delete from file system:
$hg remove <filename1, filename2...>

To remove file from repository and delete from file system as well"
$ hg remove -f <filename1, filename2,...>

To add all new files and remove all deleted files from repository:
$ hg addremove

To move or rename files in the repository:
$ hg move <oldfilename> <newfilename>

To copy files in the repository:
$ hg copy <oldfilename> <newfilename>

Commands for Commit, Revert Changes
To commit Changes to server repository:
$ hg commit
$ hg push

To commit as a particular user:
$ hg commit -u <username>

To revert all changes in local repository:
$ hg revert -a

To revert specific changes in local repositroy
$ hg revert <filename1, filename2, ..>

Commands to View Changes
To view changes between working set on your local repository and repository tip:
$ hg diff

To view changes between working set on your local repository and specific revision:
$ hg diff -r <revisionNumber>

To view changes between two revisions:
$ hg diff -r <revisionNumber> -r <revisionNumber>

To check what are changes in working set:
$ hg status

To list all changesets:
$ hg log

Commands to Update Working Set
To change working set to tip:
$ hg pull
$ hg up

To change working set with discarding any current work:
$ hg update -C

To change working set to specific revision:
$ hg update -r <revisionNumber>

To change working set to specific branch:
$ hg update -r <branchName>

To see the list of branches available for merging:
$ hg heads

Commands for Handling tags and Branches
To delete a tag:
$ hg tag -r <tagtext>

To tag a revision:
$ hg tag [-r <revisionNumber] <tagtext>

To list tags:
$ hg tags

To create new branch:
$ hg branch <branchName>
$ hg commit -m "New Branch created <branchName>"

To delete a branch:
$ hg commit - - close-branch <branchName>

To see the list of branches available:
$ hg branches

For HG Diff command setting in .hgrc file in /home/username folder: 


Commands related to Patch:
Generating a patch:
$ hg diff  >  patchfilename

Discarding all local changes:
$ hg revert -a

Thursday, February 3, 2011

Ubuntu commands

I am user of Ubuntu. I am writing this post to help people like me who forgets the stuff they used before.

How to check Installed Ubuntu version and its Codename
lsb_release -a

How to check Disk Space:
$ df -Th

Video editor in Ubuntu:
$ avidemux

To Upgrade Ubuntu Version Online:
Press ALT+F2 , then type "update-manager -d" without quotes and hit Enter key.

Mounting ISO image as a drive on Ubuntu:
$ sudo mount -o loop  ~/Desktop/filename.iso  /media/cdrom0

HOWTO: Move the Minimize/Maximize/Close Buttons back the Right Side
Hit ALT - F2
Type gconf-editor
Go to the following:
apps --> metacity --> general
Find the button_layout parameter, right mouse click, and select Edit Key
Change the value to the following:
Don't forget the colon on the left side of the text. "menu" is not necessary.

To change scree resolution from Command prompt:
$ xrandr -s 1024*768

How to change MAC address of NIC card in Ubuntu:
Type following command either in /etc/rc.local file or at command prompt:

      ifconfig eth0 down
      ifconfig eth0 hw ether NEW_MAC_ADDR
      ifconfig eth0 up

Alternate way :
  1. Install "macchanger"
  $ sudo apt-get install macchanger
  2. Bring down the interface whose MAC addr you want to change
  $ sudo ifconfig eth1 down
  3. Assign random or your choice of MAC
  $ sudo macchanger -r eth1

To determine a folder's size from the command line:
$ du  -sh  "/path/to/folder"
For example, to check the size of current directory du -sh . .

To view or cancel print Job on  Unix Printer
1. Login as a user or super-user to unix computer.
2. Use "lpq -Pprinter"  command to view printer queue.
    $ lpq -Ppsc011
3. Use "lprm -Pprinter [user_id] to cancel your job
    $ lprm -Ppsc011 g0xyzqwe

 Public key error while trying to run update command
$ sudo apt-get update
gives following error :
W: GPG error: lucid Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY D2B5F4E7C3BB95BB

Solution: Take last 8 characters in the key and run following command
$ gpg --keyserver --recv-keys C3BB95BB
$ gpg --export -armor C3BB95BB | sudo apt-key add -

To download the key on another computer and then to run on your computer :
$ gpg --keyserver --recv-keys C3BB95BB
$  gpg --export -armor C3BB95BB > key.asc

Now Copy key.asc file on your computer and run following command:
$ cat key.asc | sudo apt-key add -

To reflect the changes done in ~/.bashrc file without restarting your Terminal window:
$ source ~/.bashrc

To get Ubuntu Command prompt:
press : Ctrl + Alt + F2    or
  Ctrl  +  Alt  + F5

and to get back GUI screen (Xserver):
press:  Ctrl + Alt + F7

What to do if ubuntu hangs? Or how to restart Xserver:
press : Ctrl + Alt + Backspace
or press: Alt + Backspace
This usually restarts xserver. You need to login again to the system.

Using Bash History Effectively:
Type the following command to get a list of all related commands with their history numbers:
$ history | grep -i "search string"
Once you've found the command you want, you can execute it specifically by its number
$ !<history_command_number>

How to prevent Auto Locking the computer Screen:
1. Open file "/etc/default/acpi-support" and comment following line:

    # Comment this out to disable screen locking on resume

2.  Open "System > Preferences > Screen Saver" and uncheck following option:
     Lock screen when screensaver is active

How to Merge Multiple PDF files into single PDF file:
1. Install two pacakeges GhostScript and PDFtk tools.
 $ sudo apt-get install gs pdftk

2. Use following command to combine multiple files into single PDF file. The output file name is "singleCombinedPdfFile.pdf". The input file names are all files in the current directory, bcoz we used "*.pdf".

$ gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=singleCombinedPdfFile.pdf -dBATCH *.pdf

If you want to join PDF files in specific order then you can also use file names. 
$ gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=singleCombinedPdfFile.pdf -dBATCH 1.pdf 2.pdf 3.pdf

Wireless Networks: "Wireless is disabled"
$ rfkill  list all
You should see both the soft blocked and hard blocked as no. If either of them is yes then the connection would not be enabled. To enable type the following:
$ rfkill unblock wifi
Hard blocked: yes
This suggests that the wireless button is not switched on.

NetworkManager UI doesn't work:
1. sudo emacs /etc/NetworkManager/NetworkManager.conf
2. Set managed=true

How to get HostName from IP address?
 $ nmblookup -A 10.X.Y.Z

How to convert image into anotherformat using Command line and add border frame with color of your choice:
$ gm convert -mattecolor "#697B8F" -frame "6 6" k.jpg icon.png

Counter all lines of code including subdirectories:
find  .   -name   '*.c'   |   wc   -l

How to recover/reset forgotten Gnome Keyring Password?
$ rm ~/.gnome2/keyrings/login.keyring

How to find out the maximum RAM capacity and the number of RAM slots available in the Computer?
$ sudo dmidecode -t 16

To see complete memory information, including the info displayed by above command along with currently installed memory information (RAM speed, size, etc.), use:
$ sudo dmidecode -t memory