Skip to main content

Creating files touch, cat, vi, vim

  



* Creating File's 


1. touch  

     - To create a empty file ( 0 KB )

     - Drawback :  We can not write,modify,read file content

       # touch    test 
   
       # touch  a  b  c  

2.  cat  ( Concatenate )

      - To create file, write file , read file content.

      - Drawback  : We can not modify the file content 

       #  cat   >  test  

            WELCOME 

        Press Ctrl + d  ( To save and Quit file )

     #  cat   test    ( To read file  content )

      #  cat   >>  test  

            WELCOME 
             REDHAT 
         
        Press Ctrl + d  ( To save and Quit file ) 


3. vi  ( Visual Interface  ) 

      -  VI is a text editor tool it is used for to create file, write file , read file content,to 

           modify file content.

      - Drawback  : no colour highlighting feature 

        #  vi    test  

             Press "i"  OR "   "Insert"    Key

               WELCOME  

            Press Esc  , Press Shift+ :  ,  wq!  ( To save and Quit file )

            Press Esc  , Press Shift+ :  ,  q!   (    To  Quit file )   
     

4. VIM (  VI  Improved )

     - VI is a text editor tool it is used for to create file, write file , read file content,to 

        modify file content. Also called modal editor because without using mouse.
               
               

         #  vim    linux  

             Press "i"  OR "   "Insert"    Key

               WELCOME  

            Press Esc  , Press Shift+ :  ,  wq!  ( To save and Quit file )

            Press Esc  , Press Shift+ :  ,  q!   (    To  Quit file )


  * Mode's  Of  VI and VIM 
---------------------------------------------------------------------------------------------

1.     Insert Mode  : Normal text editing. To write and Modify file content.
ESC + i
                Entering Insert mode
i      At the cursor.
a     After the cursor.
I      Before the current line.
A     After the current line.
o      Insert a new line after the current line.
O      Insert a new line before the current line.
C       Ovewrite the whold current line.
ESC   Exit Insert mode.

   2. Ex ( Extended Mode )   : To save and Quit file. Open, search, replace
                :wq! (save and quit)
                :q! (quit without saving)
                :w (save only)
:set nu Display line numbers.
                Esc   :set nu                                       To set Line numbers 
                Esc  :Line Number                              To go to the specific line   
                :%s/searchtext/replacetex/g    

                :q!
                :q!

                :q!
                :q!

                :q!

   3. Command Mode  : It is used to perform linux yanking or file navigation operation ( cut , copy , paste, undo, redo)


            Shortcut Key                                   Purpose  

           Esc  yy                                               To copy Entire Line 

           Esc  p                                                 To  Paste Or Put 

           Esc  cc                                                To cut Entire Line 

           Esc  dd                                                To delete Entire Line 
       
           Esc  yw                                                To copy word  

           Esc  cw                                              To cut word

           Esc  dw                                              To delete word

           Esc  nyy                                             To Copy n number of lines

           
           Esc Shift + g                                      To go to the last line
  

Movement

h            Move left one character.
j             Move down one character.
k            Move up one character.
l             Move right one character.
w           Move forward one word.
b            Move to the start of the word.
e             Move to the end of the word.
(             Move back one sentence.
)             Move forward one sentence.
{             Move back one paragraph.
}            Move forward one paragraph.
^           Move to the beginning of the line.
$            Move to the end of the line.
<n>G    Move to the nth line.
G            Move to the last line.
gg            Move to the first line.
%             Move to the matching bracket.




Comments

Popular posts from this blog

sed

Sed Command in Linux/Unix with examples SED command in UNIX is stands for stream editor and it can perform lot’s of function on file like, searching, find and replace, insertion or deletion. Though most common use of SED command in UNIX is for substitution or for find and replace. By using SED you can edit files even without opening it, which is much quicker way to find and replace something in file, than first opening that file in VI Editor and then changing it. o     SED is a powerful text stream editor. Can do insertion, deletion, search and replace(substitution). o     SED command in unix supports regular expression which allows it perform complex pattern matching. Syntax: sed OPTIONS... [SCRIPT] [INPUTFILE...] Example: Consider the below text file as an input. $cat > geekfile.txt unix is great os. unix is opensource. unix is free os. learn operating system. unixlinux which one you choose. unix is easy to learn.unix ...

initramfs" file is deleted or corrupted on your RHEL or CentOS 7

Initrd/Initramfs image provides the capability to load a RAM disk by the boot loader. This RAM disk can then be mounted as the root filesystem and programs can be run from it. Afterwards, a new root file system can be mounted from a different device. The previous root filesystem which was mounted from initrd/initramfs is then moved to a directory and can be subsequently unmounted. Their are chances that either you might have accidentally deleted "initramfs" file from the /boot partition or it is corrupted due to some reason.  Then boot process will get interrupted and you will see below error: error: file '/initramfs-3.10.0-957.el7.x86_64.img' not found. Good news is you can still recover this "initramfs" by following below steps: Step 1 :  Mount RHEL or CentOS 7 ISO image on your physical server and boot from it. In case you are using HPE Prolient server you can mount this ISO image on iLO, if this is virtual environment then mount it accordingly and reboot...

nw commands

troubleshoot commands in Linux.   1. ifconfig ifconfig (interface configurator) command   is use to initialize an interface, assign IP  Address to interface and enable or disable  interface on demand. With this command  you can view IP Address and Hardware / MAC   address assign to interface and also MTU (Maximum transmission unit) size. # ifconfig   eth0       Link encap:EthernetHWaddr 00:0C:29:28:FD:4C inet addr:192.168.50.2   Bcast:192.168.50.255   Mask:255.255.255.0           inet6 addr: fe80::20c:29ff:fe28:fd4c/64 Scope:Link           UP BROADCAST RUNNING MULTICAST   MTU:1500   Metric:1           RX packets:6093 errors:0 dropped:0 overruns:0 frame:0  ...
# # #