BASIC UNIX COMMANDS
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
My name is Kavi
My name is ram
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
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
Post a Comment
Thanks for commenting, we will always respond your comment.