Git command to add all modified files

The Git command to add all modified or deleted files to the staging area is:

git add -u

The -u flag tells Git to update the index with all changes to tracked files, including modifications and deletions. This command will not add any new files that are not currently tracked by Git.

Alternatively, you can use the following command to add all modified, deleted, and untracked files to the staging area:

git add -A

–> The -A flag tells Git to add all changes to tracked files and all untracked files to the staging area. This command is useful if you have added new files that are not currently tracked by Git, and you want to add them to the staging area along with any modifications or deletions.

It’s important to note that adding files to the staging area is just the first step in committing changes to your Git repository. After adding files to the staging area, you will need to use the git commit command to create a new commit with your changes.

How do we achieve IPC ? Different techniques ?

Some common IPC mechanisms include pipes, sockets, shared memory, message queues, signals and semaphores.

Linux provides several techniques for inter-process communication (IPC) between processes. Some of the commonly used IPC techniques in Linux are:

  • Pipes: A pipe is a communication channel between two processes that enables one process to send data to the other process. Pipes are implemented using a shared file descriptor and can be either named or unnamed.
    • –> Usage : Pipes are commonly used in command-line interfaces to connect the output of one command to the input of another command. For example, the “ls | grep” command uses a pipe to send the output of the “ls” command to the input of the “grep” command.
    • A pipe consists of two file descriptors: one for writing and one for reading. A process can write data to the pipe using the write() system call, and another process can read data from the pipe using the read() system call.

  • Message queues: Message queues are a mechanism for exchanging messages between processes. They are implemented using a queue data structure and can be used to send and receive messages of a fixed size.
    • Message queues allow processes to send and receive messages in a queue-like manner.
    • To use message queues, a process first creates a message queue and then sends messages to it or receives messages from it.
    • The messages can be of variable length and contain any data that can be represented in memory.
    • –> Usage : Message queues are often used in distributed systems where multiple processes running on different machines. Here, we can use message queues to send messages between different nodes in a distributed system.
  • Shared memory: Shared memory allows multiple processes to share a segment of memory that is created by one process. This allows processes to communicate and share data more efficiently.
    • In shared memory IPC, processes can access and modify the same region of memory.
    • –> Usage : This mechanism is often used in high-performance computing applications, where multiple processes need to share large amounts of data. For example, a database server can use shared memory to allow multiple database clients to access the same data.
    • Shared memory provides a fast and efficient IPC mechanism because data can be accessed directly without any copying.
    • However, it can be challenging to implement correctly because of the need for synchronization and protection against race conditions.
    • To use shared memory, a process first creates a shared memory segment and then attaches to it. Other processes can attach to the same shared memory segment to share data.
  • Sockets: Sockets provide a means of communication between processes over a network. They allow processes to send and receive data to and from other processes running on remote systems.
    • A socket is a bidirectional communication mechanism that allows processes to send and receive data over a network.
    • –> Usage : Sockets are commonly used in client-server applications, where a server listens for incoming connections and handles requests from multiple clients. For example, a web server can use sockets to handle HTTP requests from multiple clients.
    • A socket consists of an IP address, a port number, and a communication protocol.
    • To use sockets, a process first creates a socket and then sends data to it or receives data from it.

  • Semaphores: Semaphores are used to manage access to shared resources and synchronize activities between processes. They provide a mechanism for controlling access to shared resources and preventing conflicts that can arise from concurrent access.

  • Signals: these can be used to notify processes of specific events or to request that a process perform a certain action. This is event-driven technique.

These IPC techniques can be used to implement various types of inter-process communication in Linux, including synchronization, data transfer, and message passing.

The choice of IPC technique depends on the specific requirements of the application and the nature of the data being exchanged.

Little endian v/s Big endian

Little endian and big endian are two ways of storing multibyte data types (such as integers and floating-point numbers) in computer memory.

In little endian byte order, the least significant byte of a multibyte value is stored at the lowest memory address, while the most significant byte is stored at the highest memory address. This means that when we read a multibyte value from memory, we start with the least significant byte and then move on to the next byte with increasing significance. Little endian is used by some processors, such as x86 and ARM.

In big endian byte order, the most significant byte of a multibyte value is stored at the lowest memory address, while the least significant byte is stored at the highest memory address. This means that when we read a multibyte value from memory, we start with the most significant byte and then move on to the next byte with decreasing significance. Big endian is used by some other processors, such as PowerPC and SPARC.

For example, consider the 32-bit integer value 0x12345678.

In little endian byte order, this value would be stored in memory as: LSB is stored at lowest address first.

 Address    |  Value
-------------|---------
0x10000000   |   0x78
0x10000001   |   0x56
0x10000002   |   0x34
0x10000003   |   0x12

In big endian byte order, the same value would be stored in memory as: MSB is stored at lowest address first.

  Address    |  Value
-------------|---------
0x10000000   |   0x12
0x10000001   |   0x34
0x10000002   |   0x56
0x10000003   |   0x78

When transferring data between systems that use different byte orders, it is important to convert the byte order to ensure that the data is interpreted correctly. This can be done using functions such as ntohl() and htonl() in C, which convert 32-bit integers between network byte order (big endian) and host byte order (either little endian or big endian depending on the system).

Return string from function – Bash scripting

How can we return string from a function ?

We can define a global variable and set the value in the function. This global variable can be accessed outside.

#!/bin/sh

# we created a global variable 
UPGRADE_PATH="abc"

#----------------------------------------------------------------------
# check if rpm package exists or not
#----------------------------------------------------------------------
function check_if_pkg_exist {
    PKG_NAME=$1
    echo "Checking if ${PKG_NAME} is exist"
    IS_EXIST=`rpm -qa | grep ${PKG_NAME}`
    if [[ ${IS_EXIST} =~ ${PKG_NAME}.* ]]; then
       return 1
    fi
    return 0
}


# function set the return value to global variable
function getUpgradePath {
    check_if_pkg_exist "chef-server"
    EXIST=$?

    if [[ ${EXIST} == 1 ]];then
        UPGRADE_PATH="chef"
    else
        UPGRADE_PATH="abc"
    fi

}

# we need to get upgrade path
# calling the function
getUpgradePath
echo "Upgrading from ${UPGRADE_PATH} to latest server"

String comparison in bash

Here is an example of comparing strings in bash. Also, uses logical AND operation.

ebscm_configure_status=0
MIGRATE_CHEF_DATA=""

# string comparison in bash
if [ $ebscm_configure_status == 0 ] && [ "${MIGRATE_CHEF_DATA}" != 'InProgress' ]; then
   echo "here"
fi

Regular expression – example 1

To match a word that starts with an alphabet and can be followed by any combination of alphabets and numbers in Perl, you can use the regular expression pattern ^[a-zA-Z][a-zA-Z0-9]*$.

Here’s a brief explanation of the pattern:

  • The ^ at the beginning of the pattern matches the start of the string.
  • The [a-zA-Z] part matches any single character that is an uppercase or lowercase alphabet.
  • The [a-zA-Z0-9]* part matches zero or more characters that are either an uppercase or lowercase alphabet, or a digit.
  • The $ at the end of the pattern matches the end of the string.

So, the complete regular expression ^[a-zA-Z][a-zA-Z0-9]*$ will match any word that starts with an alphabet and can be followed by any combination of alphabets and numbers in Perl.


To match a word that starts with an alphabet and can be followed by any combination of alphabets, numbers, #, _, and $ in Perl, you can use the regular expression pattern ^[a-zA-Z][a-zA-Z0-9#_\$]*$.

Here’s a brief explanation of the pattern:

  • The ^ at the beginning of the pattern matches the start of the string.
  • The [a-zA-Z] part matches any single character that is an uppercase or lowercase alphabet.
  • The [a-zA-Z0-9#_\$]* part matches zero or more characters that are either an uppercase or lowercase alphabet, a digit, #, _, or $.
  • The $ at the end of the pattern matches the end of the string.

So, the complete regular expression ^[a-zA-Z][a-zA-Z0-9#_\$]*$ will match any word that starts with an alphabet and can be followed by any combination of alphabets, numbers, #, _, and $ in Perl.


To match a word that starts with an alphabet and can be followed by any combination of alphabets, numbers, #, _, and $ in Oracle JET, you can use the regular expression pattern ^[a-zA-Z][a-zA-Z0-9#_$]*$.

Here’s a brief explanation of the pattern:

  • The ^ at the beginning of the pattern matches the start of the string.
  • The [a-zA-Z] part matches any single character that is an uppercase or lowercase alphabet.
  • The [a-zA-Z0-9#_\$]* part matches zero or more characters that are either an uppercase or lowercase alphabet, a digit, #, _, or $.
  • The $ at the end of the pattern matches the end of the string.

So, the complete regular expression ^[a-zA-Z][a-zA-Z0-9#_$]*$ will match any word that starts with an alphabet and can be followed by any combination of alphabets, numbers, #, _, and $ in Oracle JET.

Get locks in Oracle database

How to get what are the locks held in oracle database ?

You can use the Oracle database query below to get lock handles for a specific session or for all sessions in the database:

-- For a specific session
SELECT sid, type, id1, id2, lmode, request, ctime, block FROM v$lock WHERE sid = <session_id>;

-- For all sessions
SELECT sid, type, id1, id2, lmode, request, ctime, block FROM v$lock;

In these queries, v$lock is a dynamic performance view that shows information about locks currently held in the database. The columns in the view provide details about the type of lock, the object being locked, the mode of the lock, and other metadata.

To get the lock handles for a specific session, replace [session_id] with the session ID of the desired session. This will return a list of all locks held by that session.

To get the lock handles for all sessions, simply execute the second query without any modifications. This will return a list of all locks held by all sessions in the database.

It’s important to note that the v$lock view only shows information about currently held locks. If a lock has been released or timed out, it will not appear in the view. Additionally, the information in the view may not be completely up to date, as there may be a delay in the collection of lock information.

Display triggers on a table in Oracle Database

You have a table in Oracle database, and there are some triggers defined on that table. You want to know what all triggers are defined for that table.

Query to display triggers

To display all the triggers on a table in an Oracle database, you can use the following SQL query:

SELECT trigger_name, trigger_type, triggering_event, table_name
FROM user_triggers
WHERE table_name = 'your_table_name';

This query selects information about all triggers owned by the current user that are defined on the specified table, “your_table_name”.

If you want to see triggers from all users, you can replace “user_triggers” with “all_triggers” or “dba_triggers” and add a condition for the owner.

Here’s a brief explanation of the columns in the output:

  • trigger_name: the name of the trigger.
  • trigger_type: the type of trigger (e.g. “BEFORE INSERT”).
  • triggering_event: the event that triggers the trigger (e.g. “INSERT”).
  • table_name: the name of the table the trigger is defined on.

This query should help you to see all the triggers defined on a table in your Oracle database.

Example

Here, we are trying to display triggers on FND_NODES table

-- show all triggers on a table
select trigger_name, trigger_type, table_name from dba_triggers where table_name like 'FND_NODES%';

Output :

TRIGGER_NAME       TRIGGER_TYPE      TABLE_NAME
FNDSM              AFTER EACH ROW    FND_NODES#
UPNAME             BEFORE EACH ROW   FND_NODES#

Show Trigger definition

You can use the following query to display the definition of a trigger in an Oracle database:

SELECT dbms_metadata.get_ddl('TRIGGER', 'trigger_name', 'trigger_owner') FROM dual;

In this query, replace trigger_name with the name of the trigger you want to view, and replace trigger_owner with the schema that owns the trigger. The query will return the SQL statement used to create the trigger, including any trigger actions or conditions.

example :

-- query to show trigger definition
select dbms_metadata.get_ddl('TRIGGER', 'FNDSM', 'APPS') from dual;

this query will display the trigger definition.