Search

Script to create 2022 on linux terminal with a mask on the 0.

Here is a script you can run on the linux terminal to generate 2022 on the terminal using any charachter you want. With the charachter 0 covered partiall to indicate the need for mask in the new year too.



save the above script say as 2022.sh and execute it on the terminal using

2022 should appear on the terminal in random colors as shown in the figure below. Note the partial shading of the charachter 0 to indicate the mask.

Script to create 2022 On Linux Terminal

Here is a script you can run on the linux terminal to generate 2022 on the terminal using any charachter you want.



save the above script say as 2022.sh and execute it on the terminal using

2022 should appear on the terminal in random colors as shown in the figure below.

div function in C to find the quotient and reminder

While performin the division operation in a C program, we can get the reminted of division using the modulus operator. But getting quotient when the numbers are not completely divisble , for example if we divide 15 by 4, and want to find the quotient the usual divide operator will not be useful as it will give a floating point result. We can use the div function for this which is a part of the stdlib library. The div function takes two arguments, first one being the divident, the second one being the divisor.



The return value of the div fundtion is a structure of the form div_t, which has two member variables , Quotient and reminder.Thus to get the quotient and reminder we just ned to access these member variables in the return value of div.

Here is a example program.

bash script to generate fibonacci series

Here is a linux bash script to generate fibonacci series .Fibonacci series is a sequence of numbers where each number is generated by addition of the previous two numbers in the sequence.

The script asks the user to provide how many numbers of the series have to be generated and prints out the numbers in the fibonacci series as many requested by the user.



Save the script as fibonacci,sh , open the terminal and run the script using



A look into the /dev/null driver

We must have used the /dev/null to send the unwanted output from the terminal , its like a sinkhole into which we can dump any data and it is lost forever. We can only write into it but never read out of the /dev/null. For example



The string goes into the /dev/null , but does not get saved in it. If /dev/null is read, it will print nothing.

Let us look under the null device and see how this is achivedin the kernel. The null device is a charachater device, which can be noticed by listing it



The first charahcter is "c" which indicates it is a charachter device. Being a charachter driver it should have a read operation and writer file operations mapped to it. These can be found in the file mem.c . The write_null and read_null functions meant to read and write from the null device are written in the file mem.c . Let us look at the write_null



As can be seen the function does not store any data, but just returns a count of data recevied. Thus any data written into the devices does not get stored in any location and is just lost completely.

Similarly if we look at the read_null function.



We can see that the above function will always return a 0, every time is read and does not really return any data to the user space. Thus reading out of the null driver never produces any output, but the read operation succeeds everytime.

EOL while scanning string literal

The following error might come in python when working with strings that have a "\" in it.



This error is generally because of the use of the backslash in a string operation. For example , consider the string



If we want to split the string using "\" as the seperator, we can not use



The above split command will throw the EOL error. To get around this, we need the escape the special meaning of the "\" by using another "\" preceding it.



Using split function by prefixing a "\" with another "\" will ensure that we do not get the EOL error

VMplayer : make: *** [Makefile:117: vmnet.ko] Error 2 Unable to install all modules. See log for details.

A recent update on VMplayer16 version attempted to install the module for vmnet but it was unable to do so broke the vmplayer, with the error message



The log showed an error indicating some issue with the compilation of the vmnet module and was not able to generate the module for it.

The issue was in the vmplayer version 16.0, the simplest workaround for this is to download the vmplayer 16.1.2 from the site or any newer version avaialble and install the same. This issue has been fixed in the newer versions, and the vmplayer is able to lauch successfully.

Generate Indian Flag on the Linux Terminal

Here is a script to generate something close to India Flag on the linux Terminal. The output looks as shown in he figure below .


Save the file as the flag.sh and run it in the terminal, with terminal in the full screen.



Record Sound or Voice in Ubuntu

To record sound using linux/ubuntu we don't need and special softwares, a simple command line tool is available called arecord. One of the simple way to use the command in the terminal as follows.



The recording is continued as long as Cntrl+C is not pressed, recording infinitely. The recording will get saved in the file named filename.wav

If the recording needs to be stopped after a specific interval we can use the option -d



Loading modules automatically on boot

Linux kernel loads all the needed modules while booting, but some modules compiled and added later or externally might need to the loaded manually at every boot. Loading of such modules can be automated using the .conf file in /etc/modules-load.d . For example we have a file named cpu-filters.conf in the modules-load.d folder.



If we look at the modules loaded in the kernel, we can see all these three modules as shown in the figure below



Now if we comment out the lp module.

Restart the computer after commenting the lp module and search for the lp module.


It can be seen the lp is not loaded this time.

Script to find if a number is odd or even using the command factor.

Here is linux shell script which will find if a number is even or odd using the command factor.



Save the script as oddEven.sh and execute it using bash.



The factor command basically lists all the factors of the number, and by using grep we search for 2 using the option -c to count if 2 is present count will be 1 , else it will be 0.

Create screenshot using gimp

Gimp can be used to take screenshots of the screen, or specific window or regions.

Click on File->Create->Screenshot


It will pop the following menu. providing the options to either take the screenshot of the active window, or the entire screen or a specific region. It also allows to add delay in seconds to allow us the close the gimp window and open the window of which we want to take the screenshot of.



When we select the option of screenshot of a specific region, it allows us to specify delay after which we want to select the region to be taken screenshot of and also delay in seconds after which the screenshot should be taken. So it allows us to get out of the gimp window and make the selection of the area, as well as open another application if screenshot needs to be taken of another application.

Gimp Hide all dockable windows.

While working with gimp, if you want to hide all the dockable toolboxes around it, so that you can concetrate only on the image in the window, we can click on the options windows->Hide Docks as shwown


With all dockable windows hidden we are left with only the image.

Llinux Shell Script to check if a file exists

Here a linux shell script which can be used to find if a file exists or not at a given location.



Save the file as checkifFileExist.sh and execute it as shown below.



When prompted enter the file name if you want to check in the current directory or enter the full path to where the presence of the file has to be checked, and the script will show if the file exists or not .



We can use the following script if we want to pass the file name to be searched for as a command line argument.

Save the file as checkifFileExist.sh and execute it as shown below.