Printing Time Using C Language

#include <assert.h>
#include <stdio.h>
#include <time.h>

int main(void) {
    time_t t = time(NULL);
    struct tm *tm = localtime(&t);
    char s[64];
    assert(strftime(s, sizeof(s), "%x", tm));
    printf("%s\n", s);
    return 0;
}
Output:
vadakkodan@vadakkodanz:~/Desktop/Bahuleyans_Supermarket$ ./t 
02/13/22

Some format specifiers for strftime() are shown as follows : 
%x = Preferred date representation 
%I = Hour as a decimal number (12-hour clock). 
%M = Minutes in decimal ranging from 00 to 59. 
%p = Either “AM” or “PM” according to the given time value, etc. 
%a = Abbreviated weekday name 

%^a = Abbreviated weekday name in capital letters
%A = Full weekday name 
%b = Abbreviated month name 

%^b = Abbreviated month name in capital letters
%B = Full month name March 
%c = Date and time representation 
%d = Day of the month (01-31) 
%H = Hour in 24h format (00-23) 
%I = Hour in 12h format (01-12) 
%j = Day of the year (001-366) 
%m = Month as a decimal number (01-12) 
%M = Minute (00-59)

man strftime

Will give more information about it.

A modified code for my project is added below.

#include <assert.h>
#include <stdio.h>
#include <time.h>

int main(void) {
    time_t t = time(NULL);
    struct tm *tm = localtime(&t);
    char s[64];
    char tim[64];
    assert(strftime(s, sizeof(s), "Date:  %d-%b-%G", tm));
    assert(strftime(tim, sizeof(tim),"Time:  %I:%M %p", tm));

    printf("%s\n", s);
    printf("%s\n", tim);
    return 0;
}
Output:
vadakkodan@vadakkodanz:~/Desktop/Bahuleyans_Supermarket$ ./t 
Date:  13-Feb-2022
Time:  04:04 PM

Create git Repository through Terminal/CLI

I always want everything about software development through CLI. I searched, searched and searched. Everything is just noise on internet. That is why I started exploring everything my own and started making this note. These are not my blogs these are just my notes.

Install gh

Simple owrd is install a package named gh.

Technology Journal

curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null

sudo apt update
sudo apt install gh

The thing is after installing this you need to create. That is the thing.

Just publishing now. Later will clean up and update.

How to list the installed Desktop applications/packages on Ubuntu

I was trying to remove the Dolphin file manager from my Ubuntu desktop. But I don’t even remember the package name was Dolphin. I forgot the dpkg —list because I was not using it for long time even though it was my best buddy.

dpkg command

dpkg stands for Debian Package Manager- do man dpkg in Terminal to read the manual about it.

dpkg --list | grep "file manager"

I got the below thing:

vadakkodan@vadakkodanz:~$ dpkg --list | grep "file manager"
ii  dolphin                                       4:20.12.3-0ubuntu1                                                   amd64        file manager
ii  nautilus                                      1:3.38.2-1ubuntu2                                                    amd64        file manager and graphical shell for GNOME

Other Methods

1. apt list

apt list --installed

It lists all the packages including the libraries. Hey! that’s not what I want.

2. Synaptic Package Manger – GUI Package manager

I have already installed the Synaptic Package Manager. Through GUI I was able to analyse and do necessary things through that. But still I need to explore lot of options in that.

3. The best bash script

 for app in /usr/share/applications/.desktop ~/.local/share/applications/.desktop; do app="${app##/*/}"; echo "${app::-8}"; done > apps.txt

The last ‘> apps.txt’ convert the list to a text file.

Finally I purged the Dolphin file manager.

sudo apt purge dolphin

Emacs- Short cuts

To open Emacs :

Open the Terminal by pressing: Ctrl + Alt + t

Type : emacs

To Open Emacs with out a graphical window:

type : emcas -nw

here nw-stands for now window

Some shortcuts:

In emacs C stands for control key and M stands for Alt (meta) Key

C+v = view next page

M+v = previous page

C+l = moving top and bottom of the same screen

 

C+f = forward

Plural Sight: Introduction to the Bash Shell on Mac OS and Linux By Reindert-Jan Ekker

Module 4: Using bash More effectively
*- Wild card
Module 5: Filtering and Processing Text
1. Editing Text File:

Nano
vi
emacs
2. Sorting with Sort
*****command is sort
*****sort alphabetically- sort file_name
*sort based on column 2 and based on number : sort -nk2 file name
*sort based on column 2 and based on number in reverse : sort -rnk2 file name

sorting to show unique entries in a list and number of repetitions (count -c switch)
• sort file_name | uniq -c
• sort file_name | uniq -c | sort nr (numerically the sorted repetiton number in reverse order)


3. Head and Tail

• ls -S sort files by size, highest first
• head for the first 10 files
• ls -Sh | head
• ls -Sh | head -2
• ls -Sh | tail -1
• ls -Sh | head -2 | tail -1

4. Count with wc
• word count
• ls | wc


5. Grep
• grep is finding a string
• to use grep case insensitive
grep -i word
• regular expressions (learn separately)
• grep can be piped with any
• -c count occurrence
• -l shows line number of occurence
grep for multiple string
grep string*


6. Searching for files with find

• find
• find /dir -name emacs (-name is a key)
7. Replacing character with tr
8. advanced tools
awk,perl,python

JOBS AND PROCESS

1. background Jobs
• fg – for fore ground running a process
• bg – back ground running a process
back ground can be achieved just by adding an ‘&”
2. Job Control
• Ctrol Z suspends the job
• PID- process ID
• jobid

3. Killing jobs and Process
xkill —-to xwindows kill option
job id can be seen if the process started from the bash terminal
else using ps -e can see process id
ps -e | grep -chrome
pkill is very power careful before using it
Hard Kill
kill -KILL 6543
kill %jobid normally kill %1,2 etc

4. Inspecting Processes
All processes can be seen
ps -e
process based on users

ps -ef

top

shows real time process

7. Customisation:

1. Aliases
• alias gerp=grep
• \ls backslash used to avoid the effect of alias
• i set my alias for easy access of yeah folder like this
• alias yeah=”cd /mnt/Yeah”
2. Saving customisation
.bashrc .profile are the two files where you can save your customization files.
better to save customizations at the end of the .bashrc file.
3.Environment variable

env

About promt:
promt is that vadakkodan@vadakkodanz: place in terminal. I can even change that.
command for that is
echo $PS1
if make changes in .bashrc file the promt can be modified.

4. More about env command
PATH: this tells the bash where to seach for the command you have given.
I included my desktop directory to the path, so that my ise opening script and vivado script anywhere from my bash terminal

echo $PATH
to set path command is

echo ‘PATH=”$PATH ~/Desktop”‘

Editor Default:
If you are on less if you press simply the ‘v’ it will redirect you to the default editor.
If you want to change that, that too can be done in the .bashrc file

.bashrc should be added with

export EDITOR=emacs

export is an import command

5. Setting default shell

command:

cssh

shell can be seen from
echo $SHELL

chsh

eg: chsh
give password
/bin/dash