Basic Commands
Basic Commands
@move@
#mv dir1 /var/tmp/ (Moves the dir1 to specified path)
#mv file1 /tmp/backup_file1 (Move and rename)
--------------------------------------------------------
@rename@
#mv old_name new_name (same mv command is used for renaming)
--------------------------------------------------------
@remove/delete@
#rm file1 (delete regular file)
#rm -r dir1 (deletes the directory)
#rm -rf dir2 (deletes all data in directory forcefully, use carefully)
www.iteindia.in
131/13, Zone – II, MP Nagar Bhopal, 9111240646, 9981511646
Basic Directory Structure
Directory Architecture
#vim filename
1)Command Mode
2)Insert Mode
3)Exit Mode
Command Mode :-
This mode is used to run command in vim editor like copy, paste, search, delete, undo etc.
Search in Vim -
/<text> - search the <text> downwards in file
n - continue search in same direction
N - continue search in opposite direction
?<text> - search upwards in file
n - continue search in same direction
u - used to undo the last change's
www.iteindia.in
131/13, Zone – II, MP Nagar Bhopal, 9111240646, 9981511646
yank(copy) | cut (delete)
-------------------------
word - yw | dw
line - yy | dd
5line - 5yy | 5dd
25line- 25yy | 25dd
put (paste)
p - used to paste the data below cursor for line oriented data
P - used to paste the data above cursor
---
Insert Mode :-
It is Used to enter or edit text and for cursor movement within file
i - insert
a-?
o-?
I-?
O-?
A-?
---
Exit Mode :-
This mode is used to save and exit the file
:q - quit
:wq - write & quit
:w - write only
:q! - exit forcefully and abandon changes
:wq! - save & exit forcefully
--------End of Topic----------------
Class work after 2 times practice of vim editor :-
1) Search how to remove the highlights on text we are serching in file.
2) Insert the line number before every line
3) open two files in vim editor at the same time using split window inside the vim editor and work
on both of them.
www.iteindia.in
131/13, Zone – II, MP Nagar Bhopal, 9111240646, 9981511646
Find Command in Linux
------------------
Find is used to search the data anywhere in system :
#find / -name passwd {Command will search file named passwd in / , remember
this command will exactly match the case of search value, you have entered}
#find / -name *.jpg {command will search all the files in your system having
extension .jpg}
#find / -iname passwd {Command will search the value "passwd" in capital or
small letters in whole system, including all mounted partitions}
#find / -user username {command will search all the data belongs to username user
in whole system }
#find / -size +10M {Command will search all the files in system those are greater
then 10 MB in size in whole system, you can search in K,M,G}
#find / -size -10M {Command will search all the files in system those are smaller
then 10 MB in size, This command is practically not usable as maximum files in
system is below 10M}
#find / -size 10M {Command will search the files of exact 10 MB}
#find /home -ctime +3 {Command will search the data "created" before then last 3
days}
#find /home -atime -3 {Command will search the data "accessed" within last 3
days}
#find /home -mtime 3 {Command will search the data "modified" exactly 3 days
before}
www.iteindia.in
131/13, Zone – II, MP Nagar Bhopal, 9111240646, 9981511646
Redirection
#ls -l / {Command will return Standard Output on Monitor}
#ls -l / > stdout [ 1> and > is same ] {This command will redirect to output of ls -l
Command to the file stdout, you will not able to see anything on screen after
command.
#cat stdout { Now this command will show the output of previous command as the
output of ls -l / command is stored permanently in stdout file}
Assuming we are adding the user named motorola and his primary is google, but
google group doesn't exist in machine, then useradd command will return the error,
and we will store the standard error generated by command.
$find / -iname passwd > stdout1 2> stderr1 {Command will store the output in file
stdout1 and error in stderr1 file seperately}
$find / -iname passwd &> stdout_err {Command will store the output and error in
single file}
www.iteindia.in
131/13, Zone – II, MP Nagar Bhopal, 9111240646, 9981511646
Using Pipe Operator
| (pipe) Operator is used to send the output on one command to another command.
For example if we run
#ls -l /etc
Above command will generate a very long output and we are not able to see the
output in one screen, then using | operator, we will redirector the outpur of ls
command to more command :
Another example :
#cat /etc/passwd {this will show the output of /etc/passwd file in small alphabets}
#cat /etc/passwd | tr 'a-z' 'A-Z' {Command will convert the small letters into capital
letters as the output of /etc/passwd is truncated into capital letters using tr command}
#cat /etc/passwd | tr 'a-z' 'A-Z' | more {Command will send the output of cat
command to tr and tr command's output will be sended to more command}
#cat /etc/passwd | tr 'a-z' 'A-Z' > capspasswd {Finally command will store the
output in capspasswd file in capital letters.
--------------------------------------------------------------------------
#cat /etc/passwd | grep -i root {Grep command is used to grep the required output
from the long files, in this command we are trying to capture the lines where word
"root" is used. -i switch is used to ignore the case senstivity.
Create two similar files of 3 or 4 lines and check the differences between both the
files
#diff file1 file2 >> track_differences
www.iteindia.in
131/13, Zone – II, MP Nagar Bhopal, 9111240646, 9981511646
head & tail
#head -n 10 /etc/passwd
#tail -n 10 /etc/passwd
# ls -lt | head -n 10 {This command will show last 10 modified files in /etc
directory}
---------------------------------------------------------------------
tee Command
#ifconfig | tee test12 {this command will store the output of ifconfig
command as well display the output of ifconfig on screen }
-----------------------------------------------------------------
Standard Input
-----------------------------------------------------------------------
Input & Output Diagram and then 2>&1
2>&1 is used to channelize the data via pipe i.e. stderr is redirected via pipe to stdout
and then the data is stored in a file.
www.iteindia.in
131/13, Zone – II, MP Nagar Bhopal, 9111240646, 9981511646