:help keyword - opens help for the keyword we are searching
:wq - to exit from gvim after saving the file which you are in already
:w - saves the file which you are in but does not exit
:q! - exits the file without saving
:saveas file - save file as
:set nu - insets number to all the lines in file
:set nonu - deletes the numbers from all the lines
h - moves the cursor to left of the screen
j - moves the cursor down in a line
k - moves the cursor up in a line
l - move the cursor right in a line
H - Moves the cursor to the top of the screen
M - Moves the cursor to the middle of the screen
L - Move the cursor to the bottom of the screen
w - jumps forward to starting point of the next word
e - jumps forward to the end point of a word
b - jumps backwards to the start of the same word
^ - Jumps to the first non blank character of the line
$ - jumps to the end of the same line
gg - Goes to the first line of the document
G - Goes to the last line of the document
pwd - displays your current directory name
mkdir dir name - Creates a new directory with the dir name
rmdir dir name - Removes a directory with the dir name mentioned if the directory is empty
rm -rf dir name - Removes a directory with the dir name irrespective whether there are files
in the directory or not and also with the same command we can also remove files in a directory with
their respective names
ls - displays the contents in the directory which you are in
ls –l - displays the contents in the directory including time of the creation and last
visited
ls –lt - Displays the contents in the directory in the time wise (latest – earliest)
ls -ltr - Displays the contents in the directory in reverse order (earliest – latest)
cd dir name - cd is the command used to enter a directory
cp file1.txt file2.txt - copies the contents in the file1 to file2
cp -r dir1 dir2 - Copies the contents in the dir1 to dir2
mv -r - moves the files on one dir to another and removes the old dir
cat - displays the file content
history - Displays all the commands in the history
!! - repeats last command
! -2 - repeat 2 nd last command
:%s/old/new/g - replace old letter with new letter through out the file
:%s/old/new/gc - replaces old letter with new letter through out the file with conformations
:noh - remove highlighting of a word
/word - searches the word in the file
:w newfilename - when you are in a file and if you want to create a new file with different
name with the same contents you can use this command
wc -l file name - gives you the number of lines in a file with opening the file
du -sk (filename) - gives the size of a file in unix
du -sk - gives the size of complete directory
dd - After placing a cursor on a line which needs to be deleted and press
dd complete line will be deleted
dw - After placing the cursor on a word which needs to be deleted and
press dw
[email protected]
grep
grep “word search” filename - Searches and displays for the word in the given file name
grep -w “word search” filename - Searches and displays for only that word in the given file name
grep -wi “ word search” filename - Searches and displays for the word if it has any lower
case or upper case words in the file name
grep -win “word search” filename - displays the numbers of the lines in which the word is
there
grep -win -B (number of lines) “word search” filename - Displays the number of lines required
before the searched word line
grep -win -A (number of lines) “word search” filename - Displays the number of lines required
after the searched word line
grep -win -C (number of lines) “ word search” filename - Displays the number of lines required
after and before the searched word line
grep -win “word search” ./* - if you want to search in the complete
directory and displays the result and does not searches in sub directory
grep -winr “word search” . - searches and displays the result even in
the sub directory as well
grep -wirl “word search” - searches and displays the files name in
which the word is matching
grep -wirc “word search” - Displays the number of times the word is
matching in each file
Regular Expression :
. - Any Character except new line
\d - Digit (0-9)
\D - Not a Digit (0-9)
\w - word character (a-z, A-Z, 0-9, _)
\W - Not a word character
\s - white space (space, tab, newline)
\S - Not a white space (space, tab, newline)
\b - Word Boundary
\B - Not a word boundary
^ - Beginning of a string
$ - End of a string
[] - Matches the characters in brackets
[^ ] - Matches the characters Not in bracket
| - Either or
() - Group
Quantifiers:
*- - 0 or more
+ - 1 or more
? - 0 or one
{3} - Exact number
{3,4} - Range of Numbers (Minimum, Maximum)
File Handling:
Open “filename” “mode to open it” - opens a new file
Here, filename is string literal, which you will use to name your file
and accessMode can have one of the following values −
Sr.No Mode & Description
.
1 r
Opens an existing text file for reading purpose and the file must exist. This is the
default mode used when no access Mode is specified.
2 w
Opens a text file for writing, if it does not exist, then a new file is created else
existing file is truncated.
3 a
Opens a text file for writing in appending mode and file must exist. Here, your
program will start appending content in the existing file content.
4 r+
Opens a text file for reading and writing both. File must exist already.
5 w+
Opens a text file for reading and writing both. It first truncate the file to zero
length if it exists otherwise create the file if it does not exist.
6 a+
Opens a text file for reading and writing both. It creates the file if it does not
exist. The reading will start from the beginning, but writing can only be
appended.