TIPS &TRICKS

OpenSource For You - - Tips & Tricks - —Ra­manathan M, rus.cahimb@gmail.com

Clear­ing the ter­mi­nal screen

En­ter ‘clear’ with­out quotes in the ter­mi­nal and hit the En­ter but­ton. This causes the screen to be cleared, mak­ing it look like a new ter­mi­nal.

—Ab­hi­nay B, ohyesabhi2393@gmail.com

Con­vert im­age for­mats from the com­mand line in Ubuntu

‘con­vert’ is a com­mand line tool that works very well in many Linux based OSs. The ‘con­vert’ pro­gram is a part of the ImageMag­ick suite of tools and is avail­able for all ma­jor Linux based op­er­at­ing sys­tems. If it is not on your com­puter, you can in­stall it us­ing your pack­age man­ager.

It can con­vert be­tween im­age for­mats as well as re­size an im­age, blur, crop, dither, draw on, flip, join, and re­sam­ple more from your com­mand line.

The syn­tax is as fol­lows:

con­vert [in­put op­tions] in­put file [out­put op­tions] out­put file.

For ex­am­ple, we can con­vert a PNG im­age to GIF by giv­ing the fol­low­ing com­mand:

con­vert im­age.png im­age.gif

To con­vert a JPG im­age to BMP, you can give the fol­low­ing com­mand:

con­vert im­age.jpg im­age.bmp

The tool can also be used to re­size an im­age, for which the syn­tax is shown be­low:

con­vert [name­ofim­age.jpg] ­re­size [dimensions] [new­name­ofim­age.jpg]

For ex­am­ple, to con­vert an im­age to a size of 800 x 600, the com­mand would be as fol­lows: con­vert im­age1.jpg -re­size 800x600 newim­age1.jpg —Anirudh K, anirudh.3194@gmail.com

Pass­word­less SSH to re­mote ma­chine

It can be re­ally an­noy­ing (mostly in the en­ter­prise en­vi­ron­ment) when you have to en­ter a pass­word each time while do­ing an SSH to a re­mote ma­chine. So, our aim here is to do a pass­word­less SSH from one ma­chine (let’s call it host A/User a) to an­other (host B/User b).

Now, on host A, if a pair of au­then­ti­ca­tion keys are not gen­er­ated for User a, then gen­er­ate these with the fol­low­ing com­mands (do not en­ter a passphrase):

a@A:~> ssh-key­gen -t rsa

Gen­er­at­ing pub­lic/pri­vate rsa key pair.

En­ter file in which to save the key (/home/a/.ssh/id_rsa): Cre­ated di­rec­tory ‘/home/a/.ssh’.

En­ter passphrase (empty for no passphrase):

En­ter same passphrase again:

Your iden­ti­fi­ca­tion has been saved in /home/a/.ssh/id_rsa. Your pub­lic key has been saved in /home/a/.ssh/id_rsa.pub. The key fin­ger­print is:

3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A

This will gen­er­ate a pub­lic key on /home/a/.ssh/id_rsa.pub. On host B as User b, create ~/.ssh di­rec­tory (if not al­ready present) as fol­lows:

a@A:~> ssh b@B mkdir ­p .ssh b@B’s pass­word:

Fi­nally, ap­pend User a’s new pub­lic key to b@B:.ssh/ au­tho­rized_keys and en­ter User b’s pass­word for one last time:

a@A:~> cat .ssh/id_rsa.pub | ssh b@B ‘cat >> .ssh/au­tho­rized_ keys’ b@B’s pass­word:

From now on, you can log into host B as User b from host A as User a with­out a pass­word:

a@A:~> ssh b@B —Ashay Shir­wad­kar, ashayshir­wad­kar12@gmail.com

Per­for­mance anal­y­sis of code

In or­der to check the per­for­mance of the code you have writ­ten, you can use a simple tool called ‘perf’. Just run the fol­low­ing com­mand:

$sudo apt­get in­stall linux­tools­common linux­tools­generic

The above com­mand will in­stall the ‘perf’ tool on Ubuntu or a sim­i­lar op­er­at­ing sys­tem.

$perf list

The above com­mand gives the list of all the in­for­ma­tion that can be got by run­ning ‘perf’.

For ex­am­ple, to an­a­lyse the per­for­mance of a C pro­gram and if you want to know the num­ber of ca­che­misses, the com­mand is as fol­lows:

$perf stat ­e cache­misses ./a.out

If you want to use more than one com­mand at a time, give the fol­low­ing com­mand:

$perf stat ­e cache­misses,cache­ref­er­ences ./a.out —Gu­nasekar Du­raisamy, dg.gu­nasekar@gmail.com

Create a QR code from the com­mand line

QR code (ab­bre­vi­ated from Quick Re­sponse Code) is a type of ma­trix bar code (or two-dimensional bar code) first de­signed for the au­to­mo­tive in­dus­try. There are many on­line web­sites that help you create a QR code of your choice. Here is a method that helps gen­er­ate QR codes for a string or URL us­ing the Linux com­mand line: $echo “Tips and Tricks” | curl ­F­=\<­ qrenco.de

To gen­er­ate the QR code for a do­main, use the fol­low­ing code:

$echo “http://open­source­foru.com” | curl ­F­=\<­ qrenco.de

Note: You need a work­ing In­ter­net con­nec­tion on your com­puter.

—Remin Raphael, remin13@gmail.com

Re­place all oc­cur­rences of a string with a new line

Of­ten, we might need to re­place all oc­cur­rences of a string with a new line in a file. We can use the ‘sed’ com­mand for this:

$sed ‘s/\@@/\n/g’ file1.txt > file2.txt

The above com­mand re­places the string ‘@@’ in ‘file1. txt’ with a new line char­ac­ter and writes the mod­i­fied lines to ‘file2.txt’.

sed is a very pow­er­ful tool; you can read its man­ual for more de­tails.

—Na­garaju Dhuli­palla, na­gara­ju­nice@gmail.com

Git: Know about mod­i­fied files in change­set

Run­ning the plain old ‘git log’ spews out a whole lot of de­tails about each com­mit. How about ex­tract­ing just the name of the files (with their path rel­a­tive to the root of the Git repos­i­tory)? Here is a handy com­mand for that:

git log ­m ­1 ­­name­only ­­pretty=”for­mat:” HEAD

Chang­ing the HEAD to a dif­fer­ent SHA1 com­mit ID will fetch the names of the files only. This can come in handy while tool­ing the CI en­vi­ron­ment.

Fig­ure 1: Gen­er­ated QR code

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.