OpenSource For You

TIPS &TRICKS

- —Ramanathan M, rus.cahimb@gmail.com

Clearing the terminal screen

Enter ‘clear’ without quotes in the terminal and hit the Enter button. This causes the screen to be cleared, making it look like a new terminal.

—Abhinay B, ohyesabhi2­393@gmail.com

Convert image formats from the command line in Ubuntu

‘convert’ is a command line tool that works very well in many Linux based OSs. The ‘convert’ program is a part of the ImageMagic­k suite of tools and is available for all major Linux based operating systems. If it is not on your computer, you can install it using your package manager.

It can convert between image formats as well as resize an image, blur, crop, dither, draw on, flip, join, and resample more from your command line.

The syntax is as follows:

convert [input options] input file [output options] output file.

For example, we can convert a PNG image to GIF by giving the following command:

convert image.png image.gif

To convert a JPG image to BMP, you can give the following command:

convert image.jpg image.bmp

The tool can also be used to resize an image, for which the syntax is shown below:

convert [nameofimag­e.jpg] resize [dimensions] [newnameofi­mage.jpg]

For example, to convert an image to a size of 800 x 600, the command would be as follows: convert image1.jpg -resize 800x600 newimage1.jpg —Anirudh K, anirudh.3194@gmail.com

Passwordle­ss SSH to remote machine

It can be really annoying (mostly in the enterprise environmen­t) when you have to enter a password each time while doing an SSH to a remote machine. So, our aim here is to do a passwordle­ss SSH from one machine (let’s call it host A/User a) to another (host B/User b).

Now, on host A, if a pair of authentica­tion keys are not generated for User a, then generate these with the following commands (do not enter a passphrase):

a@A:~> ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/home/a/.ssh/id_rsa): Created directory ‘/home/a/.ssh’.

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identifica­tion has been saved in /home/a/.ssh/id_rsa. Your public key has been saved in /home/a/.ssh/id_rsa.pub. The key fingerprin­t is:

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

This will generate a public key on /home/a/.ssh/id_rsa.pub. On host B as User b, create ~/.ssh directory (if not already present) as follows:

a@A:~> ssh b@B mkdir p .ssh b@B’s password:

Finally, append User a’s new public key to b@B:.ssh/ authorized_keys and enter User b’s password for one last time:

a@A:~> cat .ssh/id_rsa.pub | ssh b@B ‘cat >> .ssh/authorized_ keys’ b@B’s password:

From now on, you can log into host B as User b from host A as User a without a password:

a@A:~> ssh b@B —Ashay Shirwadkar, ashayshirw­adkar12@gmail.com

Performanc­e analysis of code

In order to check the performanc­e of the code you have written, you can use a simple tool called ‘perf’. Just run the following command:

$sudo aptget install linuxtools­common linuxtools­generic

The above command will install the ‘perf’ tool on Ubuntu or a similar operating system.

$perf list

The above command gives the list of all the informatio­n that can be got by running ‘perf’.

For example, to analyse the performanc­e of a C program and if you want to know the number of cachemisse­s, the command is as follows:

$perf stat e cachemisse­s ./a.out

If you want to use more than one command at a time, give the following command:

$perf stat e cachemisse­s,cacherefer­ences ./a.out —Gunasekar Duraisamy, dg.gunasekar@gmail.com

Create a QR code from the command line

QR code (abbreviate­d from Quick Response Code) is a type of matrix bar code (or two-dimensiona­l bar code) first designed for the automotive industry. There are many online websites that help you create a QR code of your choice. Here is a method that helps generate QR codes for a string or URL using the Linux command line: $echo “Tips and Tricks” | curl F=\< qrenco.de

To generate the QR code for a domain, use the following code:

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

Note: You need a working Internet connection on your computer.

—Remin Raphael, remin13@gmail.com

Replace all occurrence­s of a string with a new line

Often, we might need to replace all occurrence­s of a string with a new line in a file. We can use the ‘sed’ command for this:

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

The above command replaces the string ‘@@’ in ‘file1. txt’ with a new line character and writes the modified lines to ‘file2.txt’.

sed is a very powerful tool; you can read its manual for more details.

—Nagaraju Dhulipalla, nagarajuni­ce@gmail.com

Git: Know about modified files in changeset

Running the plain old ‘git log’ spews out a whole lot of details about each commit. How about extracting just the name of the files (with their path relative to the root of the Git repository)? Here is a handy command for that:

git log m 1 nameonly pretty=”format:” HEAD

Changing the HEAD to a different SHA1 commit ID will fetch the names of the files only. This can come in handy while tooling the CI environmen­t.

 ??  ??
 ??  ??
 ??  ??
 ??  ?? Figure 1: Generated QR code
Figure 1: Generated QR code
 ??  ??
 ??  ??
 ??  ??
 ??  ??

Newspapers in English

Newspapers from India