Linux Cammands
Linux Cammands
12. cp -r [source directory] [destination directory] -> copying entire file into
new directory recurrsively
16. man [cmd] -> to get online manual help about the cammand
21. find -> used to find the ordinary file and directories
a. find [path] -type f -name [file_name.txt] ==> this is case sensitive
b. find [path] -type f -iname [file_name.txt] ==> this will ignore case i.e.
not case sensitive
c. find [path] -type f -iname [file_name.txt] -exec rm -f {}\; ==> find file
and remove it forcefully
d. find [path] -type f -name"*.txt" ==> to find multiple file
d. find [path] -type d -name [directory_name] ==> finding directory by name
-----------------------------------------------------------------------------------
----------------------------------------------
-----------------------------------------------------------------------------------
----------------------------------------------
-----------------------------------------------------------------------------------
----------------------------------------------
-----------------------------------------------------------------------------------
----------------------------------------------
22. grep -> find a pattern occuring in file without opening the file
grep -nr ["word to search for"] [path]
26. sed -> stream editor used to text substitution , insertion , and deletion
sed 's/[original_word]/[new_word]' [path_for_file] ==> substitute only 1st
occerance
sed 's/[original_word]/[new_word]/n' [path_for_file] ==> substitute nth
occurance
sed 's/[original_word]/[new_word]/g' [path_for_file] ==> to substitute all
occurance
-----------------------------------------------------------------------------------
----------------------------------------------
-----------------------------------------------------------------------------------
----------------------------------------------
-------------------------------------------------- V I Editor
-------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------------------------------
-----------------------------------------------------------------------------------
----------------------------------------------
-----------------------------------------------------------------------------------
----------------------------------------------
1. to create vi file
vi [file_name.txt]
3 modes of VI editor
a. cammand (can't be edited)
b. insert (press i to insert)
c. cmd line mode (press Esc and :)
2 versions of VI editor
a. Vim (vi improved)
b. Gvim (graphical vi mode)==> preferred
-----------------------------------------------------------------------------------
-------------------------------------------------------------------
cammand mode cammands
-----------------------------------------------------------------------------------
-------------------------------------------------------------------
1. to delete and cut the line
go to line
press Esc and dd
4. to paste once
Esc + p
5. to copy n lines
Esc + n yy
6. to paste n times
Esc + n p
7. to undo the chnages
Esc + u
-----------------------------------------------------------------------------------
-------------------------------------------------------------------
cammand Line mode cammands
-----------------------------------------------------------------------------------
-------------------------------------------------------------------
5. to search a pattern
Esc/pattern
6. to search and replace pattern for all lines for 1st occurance
Esc:%s/[old_word]/[new_word]
7. to search and replace pattern for all lines and all the occurance
Esc:%s/[old_word]/[new_word]/g -> g for global
8. to search and replace pattern for all lines for all occurance ignoring the case
Esc:%s/[old_word]/[new_word]/gi