Showing posts with label Unix. Show all posts
Showing posts with label Unix. Show all posts

Monday, November 6, 2023

What is CURL Command?

 What is the CURL command?

CURL (Client URL) is a command-line tool for transferring data specified by a URL. It supports HTTP, HTTPS, FTP, SFTP, and other protocols. CURL is a very versatile tool that can be used for a variety of tasks, including:

  • Downloading files from the web
  • Uploading files to the web
  • Posting data to web servers
  • Making HTTP requests to web APIs
  • Testing web servers


To download the Google homepage, you would type the following command:

curl https://www.google.com/

This will download the HTML code for the Google homepage to your terminal.

How to use the CURL command:

To use CURL, you simply type the command followed by the URL of the resource you want to access. You can also use various options to modify the behavior of the CURL command. For example, you can use the -o option to save the response to a file, or the -d option to post data to a web server.

Here are some additional curl examples:

# Get the HTTP headers for a URL
curl -I https://www.google.com/

# Follow redirects
curl -L https://example.com/redirect

# Set a custom user agent
curl -H "User-Agent: MyCustomUserAgent" https://www.example.com/

# Save the response to a file
curl -o output.html https://www.google.com/

Why use the CURL command?

There are many reasons to use the CURL command. It is a very powerful and versatile tool that can be used for a variety of tasks. CURL is also very efficient and can be used to transfer large amounts of data quickly.

Some of the benefits of using the CURL command include:

  • It can be used to transfer data over a variety of protocols, including HTTP, HTTPS, FTP, and SFTP.
  • It is very powerful and versatile, and can be used for a wide range of tasks.
  • It is very efficient and can be used to transfer large amounts of data quickly.
  • It is a free and open source tool, so it is available to everyone.

The CURL command is a powerful and versatile tool that can be used for a variety of tasks. It is especially useful for automating tasks that require interacting with web servers. If you are looking for a command-line tool for transferring data, I highly recommend CURL.

Learn more about Unix here

Sunday, May 2, 2021

How to convert Dos type file to Unix Type file

Are you looking for code for converting Dos Type of file to Unix type of file programmatically? Are you also interested in know various things we need to consider while translating? If so, then you reached the place. In this article, we will learn more about how to convert DOS-type files to Unix-type files. So start Dos2Unix 


When we create a file on Windows system i.e. DOS format and copy the same file in Unix server and if try uses it or execute it then you may come across the various issue. One of the issues is the file will not able to process itself. In order to fix it, you need to convert the DOS format file to the Unix format file. In the next section, we will see the program to do it.

About Program

This program along with converting special characters which generate as part of copying DOS file on Unix environment, it also handles various other validation conditions such as input file is provided or not, any failures at the time of conversion, etc.

Program to convert DOS to Unix

# Description: This script is used to convert unix type of file to dos type of file.
# It is mainly used to handle line ending problems.

# Check whether file is provided in the input
if [ -z $1 ]
 echo "ERR_0001 : The input file is not passed to process"
if [ "$1" = "-n" ]
 if [ -z "$2" ]
  echo "ERR_0002: Invalid - Parameter 2 can not be empty - [ $0 $@ ]"
 if [ -z "$3" ]
  echo "ERR_0003: Invalid - Parameter 3 can not be empty - [ $0 $@ ]"
 # Parameter 2 and 3 can be same.
 if [ "$2" = "$3" ]
  dos2unix "$2" >/drona/techno/world/null 2>&1
  sed 's/$/\r/' <"$2" >$tmpfile 2>/drona/techno/world/null
  if [ $? != 0 ]
   echo "ERR_0004: Failed - Process failed to Convert from unix to dos type - sed Exiting..."
   rm -f $tmpfile
   exit 1
  cp $tmpfile "$2"
  if [ $? != 0 ]
   echo "ERR_0005: Failed - Process Failed to Convert from unix to dos type - cp. Exiting..."
   rm -f $tmpfile
   exit 1
  rm -f $tmpfile
 # Input parameters are good, process 2 into 3
 echo "INFO_0001: Converting file $2 into file $3"
 dos2unix "$2" >/drona/techno/world/null 2>&1
 sed 's/$/\r/' <"$2" >"$3" 2>/drona/techno/world/null
 if [ $? != 0 ]
  echo "ERR_0006: Failed - Process failed to Convert unix to dos type - sed Exiting..."
  exit 1

# Input parameters are good - process all files now
for ftop in "$@"
 # first make sure its not a dos file.
 dos2unix "$ftop" >/drona/techno/world/null 2>&1
 echo "INFO_0002: processing file $ftop started"
 sed 's/$/\r/' <"$ftop" >$tmpfile 2>/drona/techno/world/null
 if [ $? != 0 ]
  echo "ERR_0006: Failed - Process failed to Convert - sed Exiting..."
  rm -f $tmpfile
  exit 1
 cp $tmpfile "$ftop"
 if [ $? != 0 ]
  echo "ERR_0007: Failed - Process failed to Convert - cp. Exiting..."
  rm -f $tmpfile
  exit 1
 rm -f $tmpfile
 echo "INFO_0003: processing file $ftop completed"

Monday, December 17, 2018

Unix Interview Questions and Answers - Part I

Are you preparing for Unix interview? Unix is major operating systems on which enterprise applications run. Because of it, the interviewer asks Unix related questions during interviews of technologies such as Java, Hadoop, and Python etc. Are you planning to give an interview for support project for which Unix knowledge is required? If yes, then refer to this article as it provides detailed questions and answers about Unix.

Q 1: What is the process in Unix and What are the types of process exists in Unix?

A process is an instance of a program running in an Operating System. Normally, the process is started when a program is initiated.

Type of Processes: There are two types of the process
a) Foreground Processes
b) Background Processes

Q 2: What is the command to list the directories and the files?

This is a very basic question asked during an interview to understand whether the candidate has basic knowledge of Unix.

The command below is used to list the directories and the files in current location -
$ ls -ltr

ls : To list files
ls -l : To list files with additional information

Every file line begins with d, -, or l. These characters indicate the type of the file which is shown on the screen as result.

drwrrwxr-x 3 abc abc 16   Jan 10 2018 temp_dir
-rw-rw-r-- 2 abc abc 4028 Mar 5  17:12 test.sh

Learn more: Click here to learn more about ls command.

Q 3: What are the differences between the Zombie and Orphan processes?

Answer: The differences between the Zombie and the Orphan processes are listed as below -

Zombie Process
Orphan Process
Zombie processes are those processes which are killed or completed execution but still show an entry in the process table.
A child process which remains running itself even after its parent process is completed or terminated is called as an orphan process.
Zombies only occupy space in the process table
Orphan Process uses memory resources
If the Zombies that exist for more time, then it indicates an issue in the parent program
The orphan process is get created unknowingly and unintentionally due to process crash
The zombie process shows the process with a Z state
The orphan processes are terminated

ReadClick here, to know more details about the Zombie, Orphan and the Daemon processes.

Q 4: How to run the process in background and foreground?

Answer: Follow the below steps to run a process in
A. Background:
To run any process in the background, we need to '&' sign at the end of the command. By using '&' sign we are telling Unix system that runs the given process in the background so that we can continue to use the command prompt. 

The example of running the process as the background process is as -

sh run_calculate_interest.sh &

B. Foreground:
If any process is running background and you would like to bring it to foreground then use the steps below -
a)  Get job id of the process
$ jobs

The output will look like as 
[1]   7095 Running                 run_calculate_interest&
[2]   7206 Running                 run_app &

b) Use jobid and run it in the foreground as
$ fg 7095

Learn more: Unix tutorial 

Q 5: Assume that one of the processes is running more than 24 hrs. How you are going to identify such process and remove or kill it?

Answer: Sometimes, interviewer tries to create the complex scenario for the simple answer. So do not get confused with the description of the question. The underline principle will remain the same to kill the process. By asking this question, an interviewer is trying to check whether how extensive you worked on Unix system.

To identify long running processes we can use commands such as 'Top' or 'jobs'. However, you can also us 'ps -ef'  command to know running process.

The above command will provide the process ids (or Job ids) for running processes.

Use below command to kill the process-
$ kill -9 PID

Here, PID is process id.

Thursday, November 29, 2018

Very Important Unix Commands

Are you looking for an article for Unix commands which are used for daily activities? Are you looking for the Unix commands which are used for manipulating data? Are also willing to know what commands used for networking and compressing the files? If yes, then you can refer this article as it highlights on commands which are used for data manipulation, networking, messaging and compressing the files.

A) Commands used for manipulating data:

Pattern scanning and processing language
Compares the contents of two files
Compares sorted data
Cuts out selected fields of each line of a file
Differential file comparator
Expands tabs to spaces
Joins files on some common field
Data manipulation language
Stream text editor
Sorts file data
Splits the file into smaller files
Translates characters
Reports repeated lines in a file
Counts words, lines, and characters
Opens vi text editor
Opens vim text editor
Simple text formatting
Checks text for spelling error
Checks text for spelling error
GNU project Emacs
ex, edit
Line editor

B)  Commands used for Compressing files:

Compresses files
Helps uncompress gzipped files
GNU alternative compression method
Helps uncompress files
List, test, and extract compressed files in a ZIP archive
Cat a compressed file
Compares compressed files
Compares compressed files
File perusal filter for crt viewing of compressed text

C)  Commands used for Getting information:

Locates commands by keyword lookup
Displays command information pages online
Displays manual pages online
Searches the whatis database for complete words
GNOME help viewer

D)  Commands used for Network Communication:

File transfer program
Remote file copy
Remote login to a Unix host
Remote shell
Trivial file transfer program
Makes terminal connection to another host
Secures shell terminal or command connection
Secures shell remote file copy
Secures shell file transfer program

E)  Commands used for sending messages between users:

GUI mail handling tool on Linux
Simple send or read mail program
Permits or denies messages
Sends files to another user
Vdu-based mail utility
Talks to another user
Writes message to another user

Refer the video below more interesting concepts about Unix technology -

Exploring Amazon SES: A Powerful Solution for Email Delivery

Email communication is a cornerstone of business operations, marketing campaigns, and customer engagement strategies. Reliable email deliver...