Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

GVIM Commands :

1) Commands to open the files with below format?


.txt/.rpt/.png/.html/.csv/.xls/.tcl
• Text file (.txt):
a. cat filename.txt # displays the contents of the file in the terminal
b. vi filename.txt # opens the file in the vi text editor
c. nano filename.txt # opens the file in the nano text editor
• Report file (.rpt):
a. cat filename.rpt # displays the contents of the file in the terminal
b. vi filename.rpt # opens the file in the vi text editor
c. nano filename.rpt # opens the file in the nano text editor
• Portable Network Graphics file (.png):
a. feh filename.png # opens the image file using the feh image
viewer
b. eog filename.png # opens the image file using the Eye of
GNOME image viewer
• HTML file (.html):
a. firefox filename.html # opens the file in the Firefox web browser
b. chrome filename.html # opens the file in the Google Chrome
web browser
• Comma-separated values file (.csv):
a. cat filename.csv # displays the contents of the file in the terminal
b. vi filename.csv # opens the file in the vi text editor
c. nano filename.csv # opens the file in the nano text editor
• Microsoft Excel file (.xls):
a. libreoffice filename.xls # opens the file in the LibreOffice Calc
spreadsheet program
b. gnumeric filename.xls # opens the file in the Gnumeric
spreadsheet program
• Tool Command Language script file (.tcl):
a. tclsh filename.tcl # executes the Tcl script in the terminal
b. vi filename.tcl # opens the file in the vi text editor
c. nano filename.tcl # opens the file in the nano text editor
2)Command to compare two or more files:
[diff file1.txt file2.txt]

3)Commands to File Handling (For Small files )


• Top :- gg
• Bottom:- G
• for particular line:- :<line number>
• enable line numbers:- :set number
• find the String:- /example
• Find and Replace the String:- :%s/old/new/g
• how many times particular String Present in that file:-
:%s/string//gn
• Add something before String:- :%s/\(string\)/before_string\1/g
• Add Something after the string:-
:%s/\(search_pattern\)\zs/insert_text/gc
• converting Space into newline: echo "file name" | tr ' ' '\n'
• if string present in that line delete entire line :sed -i '/example/d'
file.txt
• Unhighlight particular String: grep --color=never 'example' file.txt
• Highlight, particular String : grep --color=always -n 'example'
file.txt
• open a another file without closing the current file: :%!tr ' ' '\n'
• inserting in file: “i"
• Saving file: :w
• Closing file: :q
• delete line number x to line number y: :x,yd
• open the file present in current file in another window: :vsp
example.txt

4)Concatenate two or more files:


cat file1 file2 > output_file
5)Commands for complete path of file :
Realpath filename

6)Commands to File Handling (For large files without opening file),


write commands using awk and grep
• Count the number of lines in a file using awk: awk 'END{print NR}'
filename
• Count the number of words in a file using awk: awk '{ total += NF }
END{ print total }' filename
• Count the number of characters in a file using awk
• Find all occurrences of a pattern in a file using grep: grep -o
"pattern" filename
• Count the number of occurrences of a pattern in a file using grep:
grep -o "pattern" filename | wc -l
• Find all lines in a file that match a pattern using grep: grep
"pattern" filename
• Find all lines in a file that do not match a pattern using grep: grep -
v "pattern" filename
• Find the first occurrence of a pattern in a file using awk: awk
'/pattern/{print;exit}' filename
• Find the last occurrence of a pattern in a file using tac and awk:
tac filename | awk '/pattern/{print;exit}'
• Extract a specific column from a file using awk: awk '{print $2}'
filename

7)Find the file location where it is present or that file is present in the
current directory
• To find the location of a file on Linux, use the following command:
find / -name filename.
• To check if a file is present in the current directory, use the
following command: find . -name filename
• To check if a file is present in the current directory, use the
following command: ls filename
8)Find the Disk Space / particular file size/all file sizes/remain space in
the Disk.
• To find the disk space: df -h
• To find the size of a particular file: du -sh /path/to/file
• To find the sizes of all files in a directory: du -h /path/to/directory
• To find the remaining space on a disk: df -h /
9)How to change the mode of the Files.
chmod [options] mode file(s)

10)How to recover the deleted files.


[Isof]

You might also like