Operating Systems
How to generate or print a sequence of numbers in bash
Jan 11th
The command “seq” can be used to generate a sequence of numbers in bash. The following is the syntax of “seq” command.
seq LAST seq FIRST LAST seq FIRST INCREMENT LAST
Look at the following to understand how it works.
Example 1:
[sara@sara-desktop ~]$ seq 5 1 2 3 4 5 [sara@sara-desktop ~]$
Example 2:
[sara@sara-desktop ~]$ seq 5 10 5 6 7 8 9 10 [sara@sara-desktop ~]$
Example 3:
[sara@sara-desktop ~]$ seq 0 10 50 0 10 20 30 40 50 [sara@sara-desktop ~]$
Generally the “seq” command prints one number per line as it assumes “\n” as the separator. However the character used as More >
How to print a bash variable along with other text
Jan 10th
A general programmer tends to use a simple dollar sign ($) before each variable. However its gets difficult if a variable hash to be echoed along with some other as shown below.
An attempt to print “redtape” fails using the following method as bash attempts print value of “COLORtape” variable.
bash# COLOR=red bash# echo $COLORtape bash#
In such cases, braces should be used to protect the bash variable. The following example does that.
bash# COLOR=red
bash# echo ${COLOR}tape
redtape
bash#
How to convert a relative path to an absolute path in bash
Jan 9th
The “readlink” command can be used to convert a relative path to an absolute path. Although readlink primarily for reading value of a symbolic link, it works transparently on files and directories.
[liz@techpulp ~]# readlink ../../var/www/wiki/index.php /usr/share/mediawiki/index.php [liz@techpulp ~]#
Let us see how it behaves for an invalid path (i.e missing file or directory).
[liz@techpulp ~]# readlink ../../var/www/wiki/index.php1 [liz@techpulp ~]#
As you can see, readlink command doesn’t print anything if the file or directory is not present. Because our intention is to just convert a relative path to absolute path and not to worry about its existence, we can use “-m” option More >
How to configure apache virtual host in Microsoft Windows for safer development
Jan 6th
Typically for web development, one likes to simulate the web environment by using actual domain name as is instead of using some local IP address. It is very useful in case if you want to host WordPress and would like to copy your version of database as is from development server to the the actual hosting server. The applications like WordPress store domain names in the database while storing your posts as part of permalinks etc.
Another use for having real simulated environment is to ensure your ad slots like Google AdSense, DoubleClick etc appear without any issues. Otherwise the ads More >
How to delete a file whose name starts with minus character
Dec 21st
Sometimes an untended paste operation of screen dump results in unwanted files. If a file name starts with a minus (-) character, it is not possible to delete the file using traditional command as anything that starts with a minus (-) character is treated as one of the command line options.
For example, look at the following file “-myfile.txt“.
[sara@techpulp ~]# ls -myfile.txt [sara@techpulp ~]#
Traditional way fails to remove the file.
[sara@techpulp ~]# rm -myfile.txt rm: invalid option -- 'm' Try `rm --help' for more information. [sara@techpulp ~]#
You can use “–” option to stop “rm” command to stop expecting further command More >
How to scroll backwards on text-mode console or graphical terminal to see history of my previous activity
Dec 5th
If you are using text-mode console, you can use key combination “Shift+PageUp” to scroll up by one page. Similarly use key combination “Shift+PageDown” to scoll down by a page in console history. You need to use regular “Page Up” and “Page Down” keys and the keys on numeric keypad do not work.
Generally, the same key combinations work in graphical terminal programs like xterm, GNOME Terminal and Konsole etc. The KDE desktop based terminal program konsole adds more flexibility by supporting “Shift+Up” and “Shift+Down” key combinations to scroll down and up by a line in history. This is more convinient in More >
What is the latest version of Linux kernel and where do I get it
Dec 4th
If you are a regular user, it is recommended to use updates provided by the Linux distribution you are using. It is easier and convinient way of upgrading to the latest version of kernel. All modern Linux distributions come with an automatic updater that makes the job easy and it ensures that your system is not broken.
However if you are looking to compile your own kernel, you can visit http://www.kernel.org/ web site that provides sources of all versions of Linux kernels including the latest production and development kernels versions. Typically you would see the current stable kernel mentioned on the More >
How to convert huge number of images from one format to another in Linux
Nov 29th
The ImageMagick suite of tools provides all tools necessary to manipulate images and to convert images from one file-format to another. You can check if ImageMagick suite is installed in your system using following command.
[neo@techpulp ~]# rpm -aq | grep ImageMagick ImageMagick-6.4.0.10-2.fc10.i386 [neo@techpulp ~]#
Otherwise you can install the suite using following command.
[root@techpulp ~]# yum install ImageMagick
Coming back to the original topic of discussion, The ImageMagick suite provides a command-line utility “convert” to convert an image from one format to another. A simple use of “convert” command is as follows where it converts an image from PNG format to JPG More >
How to convert a PDF file to an image in command line of Linux
Nov 28th
The command “convert” is used to do the job. You need to install ImageMagick suite of tools that are used to manipulate images.
The following command converts a PDF file myfile.pdf to a JPG image.
[neo@techpulp ~]# convert myfile.pdf myfile.jpg
You can convert it to other image formats as well. For example, the following command converts the PDF to a PNG image file.
[neo@techpulp ~]# convert myfile.pdf myfile.png
The following command converts the PDF to a GIF image file.
[neo@techpulp ~]# convert myfile.pdf myfile.gif


Recent Comments