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.
Pages
▼
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.
#!/bin/bash
#create 2022 on terminal using any user specified character
str_dwn() {
rows=$1
s_start=$2
char=$4
str_st_row=$3
rows_end=$((str_st_row+rows))
for((i=str_st_row;i
save the above script say as 2022.sh and execute it on the terminal using
$ bash 2022.sh
What character do you want to use
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.
result=div(divident,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.
#include
#include
int main(){
int numerator=15,denominator=4;
div_t result;
result=div(numerator,denominator);
printf("Quotieint =%d,\n Reminder=%d",result.quot,result.rem);
}
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.
#! /bin/bash
num=0
echo "How many numbers in Fibonacci series are to be generated ? "
read num
fib[0]=0
fib[1]=1
fib[2]=1
for mun in `seq 3 $num`
do
fib[$mun]=$((${fib[$mun-1]}+${fib[$mun-2]}))
done
echo "The fibonacci numbers are"
echo ${fib[*]}
Save the script as fibonacci,sh , open the terminal and run the script using
$ bash fibonacci.sh
How many numbers in Fibonacci series are to be generated ?
6
The fibonacci numbers are
0 1 1 2 3 5 8
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
echo "hello" > /dev/null
The string goes into the /dev/null , but does not get saved in it. If /dev/null is read, it will print nothing.
cat /dev/null
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
ls -l /dev/null
crw-rw-rw- 1 root root 1, 3 Sep 12 00:21 /dev/null
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
static ssize_t write_null(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{
return count;
}
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.
static ssize_t read_null(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
return 0;
}
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.
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.
EOL while scanning string literal
This error is generally because of the use of the backslash in a string operation. For example , consider the string
string1="hello \ this \ that"
If we want to split the string using "\" as the seperator, we can not use
string1.split("\")
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.
string1.split("\\")
['hello ', ' this ', ' that']
Using split function by prefixing a "\" with another "\" will ensure that we do not get the EOL error
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
Unable to install all modules. See log for details.
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.
/tmp/modconfig-8DbDF1/vmnet-only/userif.c:578:13: error: too many arguments to function ‘csum_and_copy_to_user’
[scripts/Makefile.build:287: /tmp/modconfig-8DbDF1/vmnet-only/userif.o] Error 1host-4864| I005: make[2]: *** Waiting for unfinished jobs....
host-4864| I005: make[1]: *** [Makefile:1848: /tmp/modconfig-8DbDF1/vmnet-only] Error 2
host-4864| I005: make: *** [Makefile:117: vmnet.ko] Error 2
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.
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 .
horizontal() {
hrow=$2
hstart=$1
hcols=$3
char=$4
end=$((hstart + hcols))
for((i=hstart;i<=end;i++))
do
tput cup $hrow $i
printf "$char"
done
echo""
}
set_color(){
tput setaf 2
}
clear
tput setab 3
for((k=0;k<=7;k++))
do
horizontal 2 $k 160 " "
#echo $i
#horizontal 2 1 80 "*"
#horizontal 2 2 80 "*"
done
tput setab 7
for((k=8;k<=15;k++))
do
horizontal 2 $k 70 " "
done
tput setab 4
for((k=8;k<=15;k++))
do
horizontal 50 $k 80 " "
#echo $i
#horizontal 2 1 80 "*"
#horizontal 2 2 80 "*"
done
tput setab 7
for((k=8;k<=15;k++))
do
horizontal 80 $k 160 " "
#echo $i
#horizontal 2 1 80 "*"
#horizontal 2 2 80 "*"
done
tput setab 2
for((j=16;j<=23;j++))
do
horizontal 2 $j 160 " "
#echo $i
#horizontal 2 1 80 "*"
#horizontal 2 2 80 "*"
done
Save the file as the flag.sh and run it in the terminal, with terminal in the full screen.
$ bash falg.sh
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.
$ arecord filename.wav
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
$ arecord -d 10 filename.wav
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.
lp
ppdev
parport_pc
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.
# lp
ppdev
parport_pc
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.
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.
#!/bin/bash
echo "Enter the number"
read x
res=$(factor $x | grep -c 2)
if [ $res -eq 0 ]
then
echo "The number is odd"
else
echo "The number is even"
fi
Save the script as oddEven.sh and execute it using bash.
$ bash oddEven.sh
Enter the number
32
The number is even
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.
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.
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.
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.
#!/bin/bash
echo "Enter the file name to be find if it exists in the current directory"
echo "OR"
echo "Enter the full path to search for file any other directory"
read name
ls $name 2&>1 /dev/null
if [ $? -gt 0 ]
then
echo "File $name does not exist"
else
echo "File $name exists"
fi
Save the file as checkifFileExist.sh and execute it as shown below.
$ bash checkifFileExist.sh
Enter the file name to be find if it exists in the current directory
OR
Enter the full path to search for file any other directory
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 .
hello
File hello does not exist
We can use the following script if we want to pass the file name to be searched for as a command line argument.
#!/bin/bash
ls $1 2&>1 /dev/null
if [ $? -gt 0 ]
then
echo "File $1 does not exist"
else
echo "File $1 exists"
fi
Save the file as checkifFileExist.sh and execute it as shown below.
$ bash checkifFileExist.sh file1
File file1 exists
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.