CREATING File
    CREATING
FILES 
We can create files with generally 4 commands in centos7 
1)  cat 
2)  touch
3)  vi
4)  vim
1) 
“cat ” command 
It is used to create text file, It is also used to append (upgrade)
text files. Used to view the content of the file without opening it.
| 
cat
  > filename | 
To
  create file with cat | 
| 
cat
  filename | 
To
  view the file | 
| 
cat>>
  filename | 
Create
  and edit file | 
2) 
“touch” command 
Used to create empty file. It can create multiple empty file at the
same time.
| 
Command | 
Work  | 
| 
touch
  f1 | 
To create a empty file. | 
| 
touch
  f1 f2 f3 | 
To create multiple empty
  file | 
| 
touch
  /root/Documents/fs | 
To create file in
  particular location.    | 
| 
touch  /root/Desktop/file1   /root/mnt/file2 | 
To create file in different
  location same time.   | 
| 
touch
  “kuldeep malviya” | 
To create single file with
  space in name. | 
| 
touch
  .kuldeep | 
To create hidden file. | 
Creating Directory
Command = mkdir filename
1.   Used to create directory
2.   Can create multiple directory at same time 
3.   Can create a tree structure of directory 
| 
Command Name | 
Work | 
| 
mkdir
  filename  | 
To
  create folder at current location | 
| 
mkdir
  file1 file2 file3 file4 file5  | 
To
  create multiple folder at current location  | 
| 
mkdir  /mnt/folder  | 
To
  create folder at specified location  | 
| 
mkdir
  {1..5} filename  | 
To
  create 5 folders at a time  | 
| 
mkdir
  –p A/B/C/D/E/F/G/H/I/J/K | 
To
  create tree structure (folder in folder) | 
| 
du –sh | 
To
  know the size of the particular location  | 
| 
pwd | 
To
  know the location of particular folder | 
| 
which | 
To
  know the accsess file location of the particular command  | 
| 
man | 
Help  | 
| 
sudo | 
To
  give the access to particular command to normal user  | 
Copy and Move file and folders
            cp command is used to copy
files and directory
·     
mv command is used to move
file and folder 
| 
Command | 
Work | 
| 
cp source  destination  | 
To copy file  | 
| 
cp –r source  destination | 
To copy folder | 
| 
cp –r source/*  destination | 
To copy all data inside folder | 
| 
cp source/name1 
  destination/ name2   | 
To copy & rename  | 
| 
cp source/file1 destination%file2 | 
To copy , Rename and hide file/folder | 
| 
mv  source  destination  | 
To cut (move) file /folder | 
| 
mv file1  .file1  | 
To hide existing file | 
| 
mv file1   file2  | 
To rename existing file  | 
| 
mv .file1  file1  | 
To unhide file  | 
                                     Linux Directories
| 
Directory | 
Use | 
| /boot | Contain booting file. | 
| 
/root | 
Home
  directory of root user.  | 
| 
/home | 
Contain
  the home directories of all user by default. | 
| 
/etc | 
Contain
  all configuration files. | 
| 
/var | 
Contain
  log messages. | 
| 
/bin | 
Normal
  commands execution directory. | 
| 
/sbin | 
Administrative
  commands execution directory. | 
| 
/proc | 
Current
  process.  | 
| 
/media | 
External
  media device mount point (Graphically). | 
| 
/mnt | 
Network
  or local mount point (command line ). | 
| 
/opt | 
3rd
  party /software installation dir.   | 
| 
/usr | 
Entire
  installation and own software’s installation dir.  | 
| 
/lost & Found | 
Recovery
  directory (only available in the folder where any partition is mounted
  ).   | 
| 
/dev | 
Contains
  the information of all hardware components.  | 
| 
/tmp | 
Contains
  temporary files. Automatically delete the file which is not modified from
  last 10 days.   | 
| 
/var/tmp | 
Contains
  Temporary files. Automatically delete the file which is not modified from
  last 30 days.  | 
File Editor
1>
 Vim 
2>
 Vi    
Vi and vim are the file editor which can be used to create file or
edit existing files
-  There
are 3 different modes in this editors  
1) Command Mode – ( By default )    
2) Insert Mode – ( Text editor ) – Press i to
get in insert mode
3) Execution Mode – (Exit editing for save
/unsaved exit )
Switching between vim editor’s modes 
Command mode à To à Insert
mode = press “i” or “a” 
Insert mode à To à Command mode = press “esc”
Command mode à To à
Execution mode = press “ shift + : ” 
Execution mode à To à Command
mode = press “esc”
Command used in execution
mode 
In command mode we can – 
1) Copy à line , word , character 
2) Cut/delete à line , word , character 
3) Paste à line , word , character 
4) Search à line , word , character 
5) Undo / Redo 
6) Replace 
Commands for Line
·      
To copy line = yy
·      
To copy 3 line = 3yy
·      
To copy n no of line = nyy
·      
To paste line = p
·      
To delete /cut line = dd
·      
To delete n no of line = ndd
Commands for word 
·      
Copy word = yw
·      
Copy n no. of word = nyw
·      
Paste word = p
·      
Delete word = dw 
·      
Delete n no. of word = 3dw
Commands used for character 
·      
Copy character = yl
·      
Copy  n no. of character = 3yl
·      
Paste character = p
·      
Delete character = dl
·      
Delete n no. of character =
3dl
Other commands
·      
To set numbers in the lines =
:set nu
·      
To unset the line numbers =
:set nonu
·      
To search any word = /word
name 
·      
To go to the end of all lines
( bottom ) = shift + G
·      
To go to at the top in a slot
= ctrl + u
·      
  
Commands used in execution
mode  
·      
To save file = :w
·      
To quite the file ( without
save ) = :q
·      
To save & quite = :wq 
·      
To save file forcefully = :w!
·      
To quite file forcefully =
:q!
·      
To replace any word in file =
:;%s/word name