Linux

How to print a bash variable along with other text

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 delete a file whose name starts with minus character

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

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

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 a PDF file to an image in command line of Linux

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