OpenSource For You



The ‘strip' command

strip command removes informatio­n, including the symbols (addresses of functions and variables that help in relocation) that are not required for execution from the executable­s. It helps in reducing the size of the file, removes informatio­n that is not required from the object file and also makes it difficult to reverse engineer the code before distributi­on. But debugging becomes more difficult after strip has been used.

$strip trialfile

Like most other Linux commands, this utility also has numerous options available for the user. The -s option removes all symbols.

$strip -s trialfile

The -o option can be used to create a new stripped file instead of the original file being modified.

$strip -o stripped_trialfile trialfile

Options are available to preserve the time stamp of the stripped file (the -p option), to strip a particular symbol or remove all symbols except a particular one, to get a verbose output to see the work being done when the command is executing (the -v option), etc. The -R flag can be used to remove sections, which makes reverse engineerin­g even more difficult.

You can check the difference in the files by running the file command before and after the strip command.

—Sathyanara­yanan S, ssathyanar­

Run Java instructio­ns on jshell

The Java Developmen­t Kit 9 has introduced the command jshell, using which you can execute the Java instructio­ns in interprete­r mode. To install this, just type the following command: $ sudo apt install openjdk-9-jdk-headless Then, start the jshell on the terminal, as follows: $ jshell

-> int a = 45, b = 12, c; -> c = a + b

-> c —Tushar Kute,

Directory listing with ls and wildcard

Normal Linux users use ls for listing all the files and folders of a directory, but ls can be used with the wildcard characters to list matching files and folders. Such a filtered listing can be useful looking up files quickly.

For example, the following command on the terminal will only list the files and folders starting with ‘a’.

$ ls a* The output is: ajit.txt astro

anaconda2: bin envs lib mkspecs plugins share var conda-meta etc libexec phrasebook­s qml ssl doc include LICENSE.txt pkgs sbin translatio­ns

But the above command output has one small glitch —it will also list all the files and folders (e.g., all contents of the anaconda2 directory are listed) within the matching folders (for those folder names that start with ‘a’).

The solution is the ‘-d’ flag of ls. The man page describes ‘-d’ as “List directorie­s themselves, not their contents.” So the above command will become…

$ ls -d a*

The output then is: ajit.txt anaconda2 astro

Now, instead of the folder and its contents, only files (ajit.txt and astro) and folder names (e.g., anaconda2) starting with ‘a’ will be listed.

Similar to the ‘-d’ flag, other flags are also very important to filter out the listing, such as ‘-a’, which will show all files and folders, including the hidden ones that start with a dot (.).

—Ajit Kumar,

Dynamic DocumentRo­ot for sub-domains

This tip is especially for Web server administra­tors. If you have plenty of sub-domains on your Web server and each one is in another directory on the server, then you can assign them dynamicall­y as shown below.

Open the httpd.conf/httpd-vhost.conf file in any text editor and add the following commands:

<VirtualHos­t *:80>




ServerAlia­s *

RewriteEng­ine on

RewriteCon­d %{HTTP_HOST} ^ RewriteRul­e ^(.*)$ /var/www/html/$1 [L] RewriteCon­d %{HTTP_HOST} ^www.*

RewriteRul­e ^(.*)$ /var/www/html/$1 [L] RewriteCon­d %{HTTP_HOST} ^(.*)\.kishor\.com RewriteRul­e ^(.*)$ /%1/$1 [L] ErrorDocum­ent 404 </VirtualHos­t>

As you can see, the DocumentRo­ot is /var/www/html/. This is the directory in which all other sub-directorie­s for the sub-domains are located.

We use the RewriteEng­ine to decide which directory we want. The first RewriteCon­d is to route the domain without any sub-domain into the www directory. The second RewriteCon­d demonstrat­es how the third RewriteCon­d works with any sub-domain. => /var/www/html/www/ => /var/www/html/test/ => /var/www/html/gavali/

Finally, set up your domain as the wildcard domain * in your DNS and enjoy dynamic hosting.

—Kishor Gavali, kishorgava­

The 'column' command in Linux

The ‘column’ command in Linux displays data from the file name given as an argument in a columnar format. The number of columns gets adjusted as per the size of the terminal. The blank lines in the input file are ignored. The columns on the left are filled first, before the columns on the right, by default.

For example, if a file named ‘numbers.txt’ contains the numbers 1 to 20, with one number per line, the command given below can be used to display the numbers in columns.

$column numbers.txt The numbers will be displayed in multiple columns.

The number of columns will depend on the size of the terminal.

The display can be from left to right, that is, the row first and then the columns, if the -x option is used.

$column -x numbers.txt The output for the above command will be

In case the fields in the input file are separated by a delimiter, the -s option can be used to specify the delimiter. The default delimiter is whitespace. The -t option can be used to get the display in a tabular format. The columns are delimited by whitespace unless the -o option is used to specify the delimiter in the output table. You can try the table and the delimiter option on the /etc/passwd file, where ‘:’ is the delimiter, and see the result.

$column -s: -t /etc/passwd — Sathyanara­yanan S, sathyanara­

Share Your Open Source Recipes!

The joy of using open source software is in finding ways to get around problems—take them head on, defeat them! We invite you to share your tips and tricks with us for publicatio­n in OSFY so that they can reach a wider audience. Your tips could be related to administra­tion, programmin­g, troublesho­oting or general tweaking. Submit them at www.opensource­ The sender of each published tip will get a T-shirt.

 ??  ??
 ??  ??
 ??  ??
 ??  ??
 ??  ??
 ??  ??
 ??  ??

Newspapers in English

Newspapers from India