TIPS &TRICKS
The ‘strip' command
strip command removes information, including the symbols (addresses of functions and variables that help in relocation) that are not required for execution from the executables. It helps in reducing the size of the file, removes information that is not required from the object file and also makes it difficult to reverse engineer the code before distribution. 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 engineering even more difficult.
You can check the difference in the files by running the file command before and after the strip command.
—Sathyanarayanan S, ssathyanarayanan@sssihl.edu.in
Run Java instructions on jshell
The Java Development Kit 9 has introduced the command jshell, using which you can execute the Java instructions in interpreter 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, tushar@tusharkute.com
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 phrasebooks qml ssl doc include LICENSE.txt pkgs sbin translations
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 directories 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, ajitkumar.pu@gmail.com
Dynamic DocumentRoot for sub-domains
This tip is especially for Web server administrators. 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 dynamically as shown below.
Open the httpd.conf/httpd-vhost.conf file in any text editor and add the following commands:
<VirtualHost *:80>
ServerName www.kishor.com
ServerAlias www.kishor.com
ServerAlias kishor.com
ServerAlias *.kishor.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^kishor.com RewriteRule ^(.*)$ /var/www/html/$1 [L] RewriteCond %{HTTP_HOST} ^www.*
RewriteRule ^(.*)$ /var/www/html/$1 [L] RewriteCond %{HTTP_HOST} ^(.*)\.kishor\.com RewriteRule ^(.*)$ /%1/$1 [L] ErrorDocument 404 http://www.kishor.com </VirtualHost>
As you can see, the DocumentRoot is /var/www/html/. This is the directory in which all other sub-directories for the sub-domains are located.
We use the RewriteEngine to decide which directory we want. The first RewriteCond is to route the domain without any sub-domain into the www directory. The second RewriteCond demonstrates how the third RewriteCond works with any sub-domain.
www.kishor.com => /var/www/html/www/ test.kishor.com => /var/www/html/test/ gavali.kishor.com => /var/www/html/gavali/
Finally, set up your domain as the wildcard domain *.kishor.com in your DNS and enjoy dynamic hosting.
—Kishor Gavali, kishorgavali@gmail.com
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 — Sathyanarayanan S, sathyanarayanan.brn@gmail.com
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 publication in OSFY so that they can reach a wider audience. Your tips could be related to administration, programming, troubleshooting or general tweaking. Submit them at www.opensourceforu.com. The sender of each published tip will get a T-shirt.