Search

Create happy new year message on the linux terminal

We can use the following python script to generate happy new year using the diamond symbol on the linux terminal.


Save the file as happynewyear.py and execute it using



You should see the output as shown below.It can be stopped by pressing any key to exit,note that it will exit only after the display of the message.




Using the function list_is_first for finding if a node is the first node in kernel linked list

In the post Create a linked list in linux kernel 5.3 we learnt the details of creating a linked list in a linux kernel. There are number of functions available to help us manage the linked list easily once created, all of them defined in the file "linux/list.h" Let us look at the function list_is_first, which is used to find if the given node is the first node of the linked list or not.



Where list is the node which is to be checked if the it is the first node of the list or not.
head is the head node of the list.

The function list_is_first returns true of the node being checked is the head node, else it will return false. In the example below we will create a linked list with 3 nodes , one,two and three. One being the first node of the list and three being the last node. The nodes two and one both are passed to the list_is_first function and in the output we will see that when the node two is passed as the entry to be checked, the function returns false



When the node one is passed it returns true because node one is the first node of the list.

The full module code is shown below.



Save the file as linked_list_is_first.c . Use the following makefile to compile the module .



Compile and insert the module using



To see the output run the command

The output should look as shown below



We can see that for node two, the message printed is Not the first node where as for node one the function returns true and prints the message It is first node

Using the function list_del for deleting a node from the kernel linked list

In the post Create a linked list in linux kernel 5.3 we learnt the details of creating a linked list in a linux kernel. There are number of functions available to help us manage the linked list easily once created, all of them defined in the file "linux/list.h" Let us look at the function list_del, which is used for deleting one of the nodes of the list. The syntax for calling the function is



Where entry is the pointer to the list_head data in the node which we want to delete. In the sample code below we first create a linked list with three nodes ,one,two and three and print each element of the list. Then we use the function list_del to delete one of the entries.



When we print the elements of the list again, we will see in the output that only two nodes are printed and the node that was deleted is no longer printed, hence making it clear that the node did get deleted.

The full module code is shown below.



Save the file as linked_list_del.c . Use the following makefile to compile the module .



Compile and insert the module using



To see the output run the command

The output should look as shown below



We can see that as we passed the first node for deletion, only 20 and 30 are printed as part of the new list.

Python script to create a matrix on the linux terminal

Use the following script to create a matrix like background on the terminal. Save the script as matrix.py, open the terminal and run the script using

You should see an output as shown in the video below, hit any key to stop the matrix.

Thanks to the following link for the code of kbhit


Create a linked list in linux kernel 5.3

In the post "Creating linked list in linux Kernel using the list" we saw how to create a linked list in a kernel. Find below the updated code which works is tested in kernel 5.3



Save the file as linked_list.c and use the following makefile to compile the code

Compile and insert the module using the following commands



Run the command dmesg to see the linked list values being printed.

Create a welcome message on the linux terminal using python

Use the following code to create a welcome message,"Have a good day" on the linux terminal using python and ncurses library.



Save the above file, let us say as hagd.py. and execute it in the linux terminal using the command.



You should see the message have a good day appearing on the screen as shown below.



You can call this as a part of .bashrc to display the message every time terminal is launched

Create a count down timer on terminal using curses library in python

We can use the following code to create a countdown timer of 10 seconds on the terminal. It uses the curses library in python to create the timer.

Note that to be able to run the code you will need to have curses library for python installed.

You can refer to the following site to learn the installation How To Install ncurses Library on a Linux



Save the code as timer.py . Execute the code in the terminal using the command


You should see an output that looks as shown below,with the count changing every second.