Professional Documents
Culture Documents
Vi editor
vi editor is used to edit all kinds of plain text , But it especially useful for editing
VIM is the upgrade version of vi.
the programs.
Modes of VI editor :
VI editor has 3 modes :
1. Command mode
2. Input mode
3. Ex mode or Last line mode
Command mode :- The default mode of the editor is command mode . Where every key pressed is interpreter as
2
-----------------------------------------------------------------------------------------Essential Linux command
Designed By: Bishnu Charan Barik
vi raja
vi raja1
vi raja2
vi raja3
vi raja123
vi raja124
$ ls raja? -- Display the raja1,raja2,raja3 .... But whose starting with raja but
after raja only one character will be replaced
$ ls raja* -- Display the files raja1,raja2,raja3,raja123,raja124.....
Every file will be display whose starting with raja.
Note that * and ? Cannot identify those file whose are starting with .(dot) i,e hidden files .
want to access all the hidden files then
$ ls .???*
If u
Hard Links
when a file is copied, then original and copy occupy separate space on disks.
Unix allows a file to have more then one name and yet maintain a single copy on
disks.
Unix allows a file to have more then one name and yet maintain a single copy on
disk . The file
said then said to have more then one name .& they all have the same INODE number.
Create a hard link :$ ln raja raja1 (Here raja1 should not exists)
$ls -li
To show the INODE number. U will find same INODE number of
raja and raja1.
But here if u delete the original file then the link file will be orphan .
It cannot open also . If u want to open then u have to create another file in
the same name of original then it opens.
$ echo $PATH :It will shows u whole path that command searched for execution.
$ whereis cat :Display the cat path where cat is present .
if u want to change the PATH , or want to not work this commands i,e cat
then :
u have to present in Super user
copy the contents of PATH
$ export PATH=<paste here>
now $ cat :- it will shows command not found
grep :grep searches the named input FILEs (or standard input if no files are named, or if a single hyphenminus (-) is given as file name) for lines containing a match to the given PATTERN. By default, grep
prints the matching lines.
file1
grep <text> <filename>
$ grep lakshya file1 :it will give the output , thsoe lines whose have lakshya word from file1
$ grep lakshya file1 file2 :it will give the output , those lines whose have lakshya word from
file1 file2
Note :if u want to give multiple word then give with (double quote).
$ grep -i lakshya file1
Ignores the case for matching .
$ grep -v lakshya file1
Does not display lines from matching pattern . That lines will
print will print which line have no word like lakshya .
$ grep -i -v lakshya file1
This will not also display also upper case lakshya.
$ grep -c lakshya file1
Count the no of times the word lakshya is present.
$ grep -L lakshya file1 file2 file3 .....
Displaying only the filename whose have the word lakshya
Basic regular expressions :
vi file1
6
-----------------------------------------------------------------------------------------Essential Linux command
Designed By: Bishnu Charan Barik
sudhir Agarawal
manish aggarawal
v.k agrawal
$ grep [aA]g[ar][ar]wal file1
sudhir agarwal
v.k agrawal
why ?
The character class [aA] matches the letter a in both cases upper and
Lower case. And [ar][ar] matches in the 4 patterns i,e aa, ar, ra, rr.
So only 1st and 3rd case will be displayed.
$ who :shows who logged on
$ who am i :it will shows who is logging on
$ echo $ LOGNAME :only name will displayed who has logged on
$ du :It will shows the disk usages / estimate the file size
By default directory contains 4 bytes and file 0 bytes
$ du -a :Count for all files and direcories
$ du -b :It will shows in bytes format
$ du -total :It will displays the total no.
$df :Report file system disk space usages .
It shows all the drives
$ df -a :shows all file system
$df total :
shows the total of the disk usages in % format.
Compress and Decompress a file :
$ bzip2 <file_name> :- Compress bunzip file and extension should be .bz2
$ bunzip2 <filename.bz2> :- Decompress a file
$ gzip <file_name> :- Compress a file
$ gunzip <filename.gz> :- Decompress a file.
$ file * :- To show all the files
$ file a.c :- To show the specific file
7
-----------------------------------------------------------------------------------------Essential Linux command
Designed By: Bishnu Charan Barik
Change permission :
We can give some permission (read,write ,execute) to a file or directory
In linux we can give the permission to any file or directory through chmod command
There are 2 ways to Assign/Remove the permission
1. Relative Mode
2. Absolute mode
Relative Mode to give permission:
U user
+ -- Assign permission
G group
- -- Removing Permission
O Others
a -- All (User , group and Others)
r Read
w Write
x Execute
$ chmod ugo+x <file_name>
$ chmod ugo+rwx <file_name>
$ chmod go-rwx <file_name>
$ chmod u-rwx <file_name>
$ chmod a-r <file_name>
$ chmod ugo+rwx <file1><file2><file3>
$ chmod ugo+rwx *
Absolute mode to give Permission :
Here each type of permission has assign a number as follows :Read r
Write w -Execute x --
4
2
1
8
-----------------------------------------------------------------------------------------Essential Linux command
Designed By: Bishnu Charan Barik
Remembers a file permissions only can be changed by the owner of the file , But
Administrator can changed any permission of any file.
$ mkfifo :- Make fifo files also known as pipe files.
Here one terminal input will be shown in the other file.
One Terminal :
Second Terminal :
$ mkfifo raja
$ echo lakshya> raja
Cat raja
Lakshya (prited here)
10
-----------------------------------------------------------------------------------------Essential Linux command
Designed By: Bishnu Charan Barik