Skip to main content

Advance Unix Command Part1 #DOTC_Mdb

 

Advance Unix Command Part1.

 

Hello Everyone,

In Previous blogs I discussed about basic Unix command which is commonly used. Today I will discuss some advance command of Unix which is mostly used in organization.  Please see my below blogs related to Basic Unix command for your reference.

https://dheeraj60.blogspot.com/2020/08/basic-and-some-advance-command-in-unix.html

https://dheeraj60.blogspot.com/2020/08/basic-and-commonly-used-command-in-unix.html

Let’s Start with Unix command.

Find Command to find the modified files 30 days ago.

Note : We can give any number of days

Important : -mtime +30 means you are looking for a file modified 30 days ago and -mtime -30 means less than 60 days.

Command is as below:

find /home -iname "*.txt" -mtime - 30 –print

Find Command to Display  content of file on screen that were last modified 30 days ago.

find /home/  -iname "*.txt" -mtime -30 -exec cat {} \;

Below is the output of above commands in putty Terminal.



 Before finding the word count of any file we need to understand below command first .

wc : wc command is used to find the word count

$ wc - l dheeraj.txt

Above command will give you the count of text

Using Find command we will see count total number of files using wc command.

find /home -iname "*.txt" -mtime -30 | wc –l

Find command to get List all mp4s that were accessed exactly 30 days ago:

find /home/ -iname "*.mp4" -atime 30 -type –f

Note : -type f – Only search for files  not directories.

Below is the output of above command in putty terminal.

 


Let discuss about SED command in Unix : SED command in UNIX is known as stream editor and it can perform lot’s of function on file like, searching, find and replace, insertion or deletion. SED command in UNIX is for substitution or for find and replace by using SED command we can edit file without opening it . We can use it both in vi editor or by using cat command .

Let’s take example I am writing simple text by using sed command as below :

cat > dheeraj.txt

Welcome to Diksha Oracle Training Centre.

Welcome to Diksha Oracle Training Centre.

Welcome to Diksha Oracle Training Centre.

 

File created .

Now we can use sed command to replace the text in a file from Diksha to Sakshi by using sed command .

Below is the command :

$ sed 's/Diksha/Sakshi/' dheeraj.txt

After issuing this command text is replaced from Diksha to Sakshi .

Below is the output in putty terminal for your reference.



 

If we want to replace the character of 2nd occurrence in text by using sed command we use below :

cat > dheeraj1.txt

Welcome to Diksha Oracle Training Centre. Diksha Training

Welcome to Diksha Oracle Training Centre

Now we need to replace 2nd occurrence of Diksha to Sakshi by using below sed command.

$ sed 's/Diksha/Sakshi/2' dheeraj1.txt

After issuing this command the 2nd appearance of Diksha will be replaced to Sakshi. You can put any number as per your requirement.

Please see the output of above command in putty terminal.



 

Replacing all the occurrence by using sed command .

cat > dheeraj2.txt

Welcome to Diksha Oracle Training Centre

Welcome to Diksha Oracle Training Centre

Welcome to Diksha Oracle Training Centre

Sed command

$ sed 's/Diksha/Sakshi/g' dheeraj2.txt

Here g means global . It will replace to Diksha to Sakshi wherever it finds in text file.

Below is the output in putty terminal for your reference.



 

Head and tail command in Unix : This command is commonly used in Unix when you check the long file to see the status.

Note : This command basically used to check the log file for any processes or also you can use to see some pieces of code .

Head command : $ head -10 dheeraj2.txt

It will give the first 10 line from the text file

Tail command  : $ tail -10 dheeraj2.txt     

It will give the last 10 line from the text file

Note : I use 1 and 2 only since my text file is small .

Below is the output of command in putty terminal.



Grep is a Unix command-line tool used to search for a string of characters in a specified file. The text search pattern is called a regular expression. When it finds a match, it prints the line with the result. Grep command can be used in find and other command such as for process checking in Unix .

Basic Grep Command is as below :

$ grep Training dheeraj2.txt

$ grep Training *.txt

Here * means all .

Below is the output in Putty Terminal.



Through grep command to find whole word only we use below command from home directory , just append –w to the grep command

$ grep –w Diksha *

Note : –w is omitted, grep displays the search pattern even if it is a substring of another word.

To Ignore Case in Grep Searches

$ grep –i Diksha *

Note : -i operator to search files in the current directory for Diksha

Below is the output of above grep command in Putty Terminal for your reference.



Using Grep command to include all subdirectories in a search, add the -r operator to the grep command.

$  grep -r Diksha *

$ grep - rw Diksha *

We know -w operator to show whole words

Below is the output of above grep command in Putty Terminal.



 

To find Particular Process through Grep command we can use ps –ef and through pipe we can use grep command to search that particular process

$ ps –ef  

Above command will give all the process ID which is running in the system.

If I want to see particular script like abc.sh and it’s process id then we use below command by using grep

$ps –ef |grep abc.sh


Below is the output of above commands in Putty Terminal.

 


Note : Still Lot’s of commands needs to be discussed as we can use grep in find commands and also we have lots of other commands as well which I will cover in next blog .

Please go through this blog carefully and let me know if you have any questions . In next blog I will try to cover all the important commands in Unix as well as some small shell scripts. All this command from this blog and my previous blogs are important when you try to start writing shell script . Still so many commands are missing which i will include in next blog.

Thanks.

 

 

 

 

 

 

 

Comments

Post a Comment

Popular posts from this blog

SQL and Classification of SQL in Oracle Database #Diksha Oracle Training Centre

  SQL and Classification of SQL in Oracle Database.   SQL is Structured Query Language , which is used for storing, manipulating and retrieving data stored in a relational database .SQL is the standard language for RDBMS. All the Relational Database Management Systems (RDMS) like Oracle, MySQL, Sybase, Informix, IBM DB2 and Microsoft SQL Server use SQL as their standard database language. Oracle is one of the more secured database as compared to other databases. Importance of   SQL : SQL and PL/SQL is a backend process where all data is stored and retrieved in GUI which created either by any programming languages like Java, C++, PHP etc. so we need to have very secure database so that there will be no impact for users. SQL allows users to access data in the relational database management systems. SQL is used to communicate with a database.SQL and PL/SQL allows users to create and drop databases tables , views , stored procedures , functions , packages , trigger et...

Materialized View uses and Benefits in Database #DOTC_Mdb

Materialized View uses and Benefits in Database. Hello Everyone, Today we will discuss about Materialized view as it’s play important role in database. We already discussed about Simple Views and complex views in my previous blog. Before Materialized view go through my previous blog which related to simple view. https://dheeraj60.blogspot.com/2020/05/benefits-of-creating-and-using-view-in.html As we know View is not a database object and not like table which is stored in database, but view can be created from base table a view is an SQL statement that’s stored in the database. This statement, or view, has a name.A view looks and acts a lot like a table. It has columns and rows, and can be included in SELECT queries just like a table. In other word we can say View is a virtual/logical table which is basically used for security purpose. Let’s understand   about   Materialized view : A materialized view is a view that stores the results of the view’s query. Whenever you que...

Top 50 Interview Questions On SQL and PL/SQL #DOTC_Mdb

                    Top 50 Interview Questions On SQL and PL/SQL. Today we will Discuss Top 50 interview questions and answers of SQL and PL/SQL which is frequently asked in interview.     Question 1: What is SQL and Classification of SQL? Answer SQL is a Structure Query Language which is vastly used in RDBMS database like Oracle, Sybase, DB2 , Microsoft SQL server etc.   Classification of SQL is as below: DDL (Data Definition Language):  Commands are  create , alter , drop , truncate etc DML (Data Manipulation Language) : Commands are  insert,update and delete . TCL (Transaction Control Language ) : Commands are  Commit , Rollback and Save point. DCL (Data Control Language) : Commands are Grant , Revoke Question 2:    What is meant by Joins? What are the types of join? Answer Joins are basically used to extract/get data from multiple tables using s...