Skip to main content

Complete Basic Unix Command

 

BASIC UNIX COMMANDS 


Every developers must know this basic Unix commands, if you are from computer background or if your going to work as a support or in testing team, this are the some important basic commands will be used especially cat, grep, vi editor etc.

Basic Unix Command



mkdir 

Create a new directory. 

mkdir oracle_retail


ls

It is used to list the content of directories like files and directory of that directories.


cd

Change to directory

cd oracle_retail

It will move to oracle_retail directory when you are in created folder

Ubuntu/home/documents$ cd oracle_retail moves oracle retail folder

Ubuntu/home/documents/oracle_retail$ cd..

Ubuntu/home/documents$ ----- it will return to the one previous directory.


touch

It is used to create empty content files, just it will create a new file name only not any content in that file, 

touch newfile1.txt


pwd

It will display the present working directory

Home/documents/oracle_retail/


Importance of Cat Unix command


cat command is used in three purposes.

  • To display the content

  • Create a file and to enter the content to the particular file

  • Merge the two file we can copy the same content to another content.

cat > file_name

This command will be used to create a file and also content can be saved inside the file.

cat > newfile2.txt press enter

Oracle retail is used by merchandiser and warehouse. Ctrl+D

Now new content is created to save this press CTRL + D into file.

cat file_name

This will used to display the content inside the file which we created.

cat newfile2.txt press enter

Oracle retail is used by merchandiser and warehouse.

cat > newfile3.txt press enter

Welcome to RMS ctrl +D


cat file1 file2> file3

It is used to merge two contents and copying to one file

File 1 has some content and file 2 has some content, so this both the content are copied to new file 3

cat newfile2.txt newfile3.txt > newfile4.txt

cat newfile4.txt

Oracle retail is used by merchandiser and warehouse. 

Welcome to RMS


Ls based command in unix


ls *.extension

It will display all the files for the given extension

ls *.txt

It is used to display all the text files which are present in the directory.


ls *.c

It will display only dot C files


ls*.py

It will display only python files


Copy and Move basic unix command


cp file_name1 file_name2 

It is used to copy the files or directory.

cp newfile3.txt newfile5.txt

cat newfile5.txt press enter

Welcome to RMS


mv filename path

move the file to the particular path

mv newfile4.txt home/documents

it will moves the file from oracle_retail folder to documents folder.

Other basic unix command


head

This command is used to display top 10 lines of the file

head file_name


tail

This command is used to display last 10 lines of the file

tail file_name


tac

tac file_name

It is similar to cat command but here It display the content lines in the reverse order, from the last line to first line.


more

If the file contains lot of lines means.. 

While displaying it will show only limited content only, because of screen size is small, 

For example:

cat oracle1.txt

line1

.

.

.

.

.

.

.

.

.

line40


So while displaying it will show only like this in the screen for the particular screen size.

line 28

line 29

line 30

.

.

.

.

.

line 40

By using more command

more oracle.txt

line1

line2

.

.

.

.

Line 15

--more –(75%) 

Now press enter to display the remaining content.

More command is used to display the content like cat command, but here we can display the large content by pressing enter key/ space bar key.


id

It will display id of the user / group


clear

It is used to clear the screen 



Diff command

This command is used to give the difference between two files.

diff file1.txt file2.txt

cat file1.txt

This is Kaviarasan

cat file2.txt

This is Kaviarasan

Welcome to unix command

cat file3.txt

I created a unix command

diff file1.txt file2.txt ---- it will shows the difference of two files ‘This is kaviarasan’

la2

> Welcome to UNIX commands

diff file1.txt file3.txt --- here is no difference between the two filles.

This is Kaviarasan

---

I created a unix command


ping

It will used to check the connectivity status of the server.

ping any_domain/server/

ping google.com

if there is internet connection means it will show the bytes and all the results.

It will run continuously, to stop that press CTRL + Z

ping google.com

if there is no internet connection means it won’t show any details

It will show an error message: Temporary failure in resolution


history

It is used to review all the commands which we have entered in the window.


hostname

display the hostname


hostname -I IP address

It will gives an IP address


chmod

It is used to change the user or group permission to access.

For example:

cat file1.txt

Hi, this is Kaviarasan Manoharan

To give permission to this file we use chmod

chmod u=r  file1.txt

Now to check this 

vi file1.txt

click I to go to Insert mode

It will throws an error of warning message Changing a read only file.

Incase if you trying to change, while saving the file it will throws an error that will be ready only option is set.


nl - display number of lines with content

nl file1.txt

  1. My name is Kavi

  2. My name is ram

  3. My name is rolex

wc - display number of line, words and characters with the file name

wc file1.txt

3 lines 12 words 45 characters file1.txt

Output: 3 12 45 file.txt

uniq - It is used to remove duplicates of file content.

Note: It can remove only continuous duplicates

vi file1.txt

My name is Kavi

My name is Kavi ----- duplicates

My name is ram

My name is sam

Uniq file1.txt

My name is Kavi

My name is ram

My name is sam



rmdir --- removes the specified directory (need to be empty)

Note: It can remove only empty directory, so it throws an error failed to remove directory.


rm -- remove specified file 


Importance of grep command


It is filter to search for the given pattern which is in the file content.

Syntax : grep pattern file_name

For example

cat file1.txt

‘Hi this is eduflee and one of the learning portal’

grep eduflee file1.txt

‘Hi this is eduflee and one of the learning portal’

grep t file1.txt

‘Hi this is eduflee and one of the learning portal’

grep -c “t” file1.txt

2

It will display number of ‘t’ in the particular file present in each and every line

For example:

My name is ram

My name is kavi

My name is rolex

grep -c “a” file1.txt

3 Three lines contains “a”

grep -h “a” file1.txt

My name is ram

My name is kavi

My name is rolex

grep -l “o” * ---- l is used to display the file which are contains the pattern.

file1.txt

file2.txt

file3.txt

so in all this files o is available

grep -n “kavi” file1.txt --- It will display all the file with number that the line present

2: My name is kavi


grep -v “kavi” file1.txt -- It will display all the line except “kavi”

My name is ram

My name is rolex


grep -o “kavi” file1.txt -- It will show only the matched pattern only if it is present

kavi

grep -o “a” file1.txt

a

a

a

a

a


grep -e “pattern” -e “pattern” - It will used to show multiple search pattern

Example

grep -e ”kavi”  -e “rolex”

My name is Kavi

My name is rolex

grep ^My file1.txt - it will used to show that all the lines should start with the pattern

MY name is kavi

MY name is ram

MY name is rolex


grep m$ file1.txt - it will used to show that all the lines should end with the pattern

My name is ram

Here the name should end with end of the word should be m


grep -i “m” file1.txt - it will show all incase sensitive words it will display “m and M”

My name is Kavi

My name is Ram


Most important Vi – EDITOR Unix command

Press vi to open the editor without any file name.

vi file_name to open the editor with file name.

vi is used to insert a content inside the file by using editor.

It contains two mode: Insert mode and Command Mode

vi press Enter

~

~

~

~

Press I now

Now we can able to Insert any content inside this editor file

To change from Insert mode to command mode we will press ESC key, so in the bottom the INSERT will disappear

In command mode

If we press H and L for Navigation

  • H is used to move the cursor towards right

  • L is used to move the cursor towards left

  • J moving cursor downwards

  • Upper Navigation or k  is used to move the cursor upwards.

INSERTION

  • I for Insert

  • a is used to move the cursor and can be able to see the rows and columns of the particular line the cursor placed. (Insertion begins after the cursor)

  • A Insertion insertion begins at the end of the line

  • o is used to create a new line that will be appeared after the cursor

  • O is used to create a new line that will be appeared above the cursor

Copy and Paste

Move the cursor to the current line in the command mode, and press yy now the line will gets copied

Now for pasting press p to paste the command line

TO SAVE

After completing the edition in the insert mode, now to save we need to move to command mode by using ESC key.

Press :w is used to save the content.

To give the file name for the content and to save the file

Press :w filename


CONCLUSION

I hope now you got some ideas, related to the above content.

So if anyone having any doubt in this article means kindly reach out us we will explain more clearly in official mail.

Frequently Asked Interview Questions related to Unix

  • cat file_name
  • grep command
  • vi editor
  • how to save vi editor 
  • how to insert into vi editor.
  • how to clear unix command.

Comments

Popular posts from this blog

Oracle SQL Interview Questions Series 1 [Basic]

Oracle SQL Interview Questions Series - 1 Oracle SQL Interview Questions covered in Eduflee, so complete all the series to get placed into the IT company. At present Structured Query Language is very important to enter into the Software company. After completing all the Interview series, you can crack many interviews with 100% assurance from my experience. Basic Questions for SQL interview Schema => User Records => Rows Fields => Columns Result set => Output 1, What are the Schema Objects in Oracle SQL ?     Table, View, Materialized view, Sequence, Synonyms, Index are the schema objects in SQL.     Table => Basic Unit of Storage [Rows and Columns]     View => Logical Representation of subject of records, It does not contains any data. So here data is logical.     Materialized View =>   It contains the data, it is also called as Snapshot. It contains data physically.     Sequence => It is a Numeric Value Generator     Synonyms => used to provide alternate nam

Class 3 Functions in Oracle SQL

Functions in Oracle SQL Functions is one of the important features in Oracle SQL, with the help of this functions we can able to get the result as per our requirement. Functions in Oracle SQL contains Single Row Functions, Multiple Row Functions. Mainly those functions are used to returns value based on the input that which we given. And practicing this functions in oracle SQL, one can able to master in query writing. Functions is used to perform some actions like doing any calculations, grouping the data, conversion in type, date conversion etc. Types of Functions in Oracle SQL Functions in oracle is classified on the basis of the input which we are giving and getting the output, and they are: - Single Row Functions - Multiple Row Functions Single Row Functions in Oracle SQL Single Row Functions works on the single rows which will shows the result for that single rows only. If "n" number of inputs to give "n" number of outputs. From the above figure explains about

Learn SQL From Scratch to Advanced topics

Learn SQL from Scratch to Advanced  Nowadays, many IT company moreover depend on SQL  only. So this is one of the basic query language to start for new developers. So track or to be master in SQL, the below topics should be covered. List of Basic Topics :- 1, Should know what is frontend and backend developer  2, What is DBMS, RDBMS ? 3, What is SQL ? 4, What are the database are there ? Beginner Level SQL topics  This are some beginner level SQL topics, if you are new to SQL this are the topics that should be covered first. 1, Oracle Basics  2, List of Objects in SQL   3 , Clause and its usage   4, Functions  5, Sub Query  6, Joins  7, Decode and Case 8, Constraints 9, Important Data Dictionary Table like user_source, all_source, user_tables etc.., Intermediate Level SQL topics (Creating Objects)  When we are entering into objects this below topics should be covered. In  this topics that we are creating database objects like tables, views, sequences, synonyms etc. 1, Data Definitio