Linux

  • Linux is started around 1991 by Linus Torvalds.
  • Open Source
  • Linux is a multi-user & multi-tasking OS.
  • Linux is "Case-sensitive".

Linux distributions :

  • Redhat
  • Centos
  • Ubuntu
  • SusLinuxux
  • Mandriva
  • Ferodo
  • Debian
  • Gentoo
  • Slackware      

Linux File Structure:

home:   

  • Users' information
    •    Reddy
    •    Rama
    •    Lakshmi
    •    Krishna

bin:    

  • Contains of binary files (ls,mkdir,cd....etc)
    • sbin:     System-bin (Contains of binary files)   
    • bin:       Normal Users can access
    • sbin, bin:  Root user can access

Types of users:

  • Admin User-----------Super User--Root User
  • Normal User
  • System User---------[After installing the packages System user will create them automatically]

etc:       
        All configuration files ---------------------------------[ password,shadow,group & sshd_Config ]
lib:
Proc:    
        Process information ----------------------------------------------------------[ meminfo, cpuinfo ]


opt:     
By default empty.
3rd-party packages installed here.
temp: It can be accessed by any user
dev:        Contains all devices information -----------------[ Printer info, Scanner machine info.......etc..! ]


How to know which version we are using?
cat /etc/redhat-release
Basic Commands:

  • mkdir <dir_name> ------------> empty dir only
  • mkdir -v <dir_name>                                        (-v -----Verbos)----(display a message)..     
  • mkdir -vp <dir_name>  <dir_name>             
  • mkdir -vp <dir_name>  <dir_name> <dir_name>  
  • mkdir -vp <dir_name>  <dir_name> <dir_name> <dir_name>  ---------------------------(-p -----parent)
  • mkdir -m 700 <File_name>
  •  rm -rf <dir_name>----------------------------> non-empty dir                             r ----Recursive
  •  rm-f <File_name>------------- ---------------> Files only f ----Forcefully
  • ls -l--------------------------->  long listing
  • ls -la--------------------------> hidden files also
  • ls -lt-------------------------->  last access time   (top)                           l ---- Long list
  • ls -ltr-------------------------> last access time    (down)              t ---- Access time
  • ls -lh-------------------------> Human readable format        r ---- Reverse
  • ls -li--------------------------> display the inode number
  • pwd--------------------------> print working dir
  • tree
  • touch <File_name>--------> create a empty file / time stamp
  • cd------------------------------> Change directory
  • cd ..  ---------------------------> One level up
  • cd ../..  -------------------------> Two levels up
  • cd ../../.. -----------------------> Three level up
  • cd ~ (Tilt symbol)-------------> User home directory
  • cd - (ifen symbol)-------------> goto previous working dir.

File Maintenance Commands:

  • find . -type -f -----------------------------all the Two files in the current dir  [. current dir]
  • find . -type -f -empty ------------------ all empty files
  • find ~ -type -f -empty ------------------all empty files on user HD
  • #find / -type -f -empty -----------------Empty files in entire server 
  • find . -type -d -----------------------------Find dire in current dir 
  • find . -name "devops" 
  • find . -empty 
  • find . -type - -empty --------------------empty dir 
  • find ~ -type -f -empty ------------------all dir on user HD 
  • #find / -type -f -empty -----------------entire server find dir
        umask default_dir default_File

  • root            0022             755                        644 
  • Normal_user   0002            775                         664

===============================================

Base premission for dir                0777                         0666
                                 0022                         0022
                                                           755                           644                                                                 
Base permission for file                0777                          0666
                                                  0002                          0002   
                                                            775                            664        

  •   r------read---------->4 
  •   w-----write--------->2
  •   x------execute------>1
                                                                    

  •  7    5    5
  •   |     |     |
  •   |     |     Other     (0)
  •   |     Group           (g)
  •   Owner/group     (u)
chmod : 
  • Change mode
  • Change the permission for files or dir 

syntax:- chmod <Permission> <Dir/file_name>

  • chmod 000 devops.txt /  chmod ugo-rwx devops.txt
  • chmod 444 devops.txt
  • chmod 744 devops.txt
  • chmod  -R  777 devops----------[Change the permission all sub-dir also.]  [ -R-------recursive]
  • chmod        +r     devops.txt  ----- set read permission to ugo   
  • chmod  ugo+r     devops.txt  -----  same as above
  • chmod  ugo+x    devops.txt
  • chmod  ugo+w   devops.txt
  • chmod      u+rwx,  g+r,  o+x    devops.txt

chown:

  • Change Owner
  • If you want to change owner, you must have to switch root users.
  • sudo su -

Syntax :- chown <User_name> <File_name>

 chgrp:

    • Syntax :-  chgrp  <Group_name> <File_name> --------------------default group--wheel]
    • chown <User_name> : <Group_name>  <File_name>
    • chown              reddy  :    testgrp               devops.txt
    • chown  -R root devlops/  -----------------------------------------[ Change the owner for dir ]

    cp:  Copy

    • Copy files/dir one location to another location.
    •  cp  <file/dir_name> <Destination_dir>
    •  cp     devops.txt             Devops/
    •  cp     devops.txt             /temp
    •  cp     devops.txt             /etc
    • .
    • cp -r  python         Devops/                 [if you want to copy the directory mentioned(-r)]
    • cp -r  python         /temp
    mv:    Move/ Rename

    If you wan to rename the file/directory.

    • mv <Old_name> <New_name>
    • mv   devops/           azure /  
    • mv   devops.txt       azure.txt
    If you want to Move the file/directory.

      • mv   <Source> <Destination>


      file <Provide file path here>

      •  with help of this command you can able to know what type of file it is, you can find below ex.,
      • ASCII test
      • Empty file
      • block special

      mv:  Word Count

      • wc -l  <File_name>             Only line number
      • wc -w <File_name>            Only word number
      • wc -c  <File_name>            Only character count number
      • wc      <File_name>             it will display the line number
      ln:  
      • link 
      • It will create the link b/w  files
      Hard-Link:

      1.  What are the permission have origional file same link (ln) file also have.
      2.  Inode also same in Hard link
      3.  But we could not able to find which file is origional in between two link (ln) file.
      4.  The file size same in both (Origional file   &  Hard link file also)
      •                   5 GB
      •  ln /opt/flipkart/flipkart.log  /tmp/flipkart_ln_file.txt
      •                                                      5 GB

      Soft-Link:

      1. The link number it will not change when you create a Soft-link.
      2. The file starting with (L) means Soft-link.
      3. The link file and origional file size will be different
      4. Once you delete the origional file, the Soft-link can't able to access.
      5. The inode will be different to origional and Soft-link
      •                   5 GB
      •  ln  -s  /opt/flipkart/flipkart.log  /tmp/flipkart_ln_file.txt
      •                                                      5 KB

      Editor:  

      • yum install vim -y
      • :se nu
      • :se nonu
      • /<Serch_here>
      • :<line_number>          [ jump to the particular line numner ]
      • dd

      Text Reading/Display Commands

      • echo Hello Hi
      • echo   Hello                             Hi
      • echo "Hello                             Hi"
      • echo  'Hello                             Hi'
      cat  <File_name>                         display the content ]
      cat  -n <File_name>                     [ along with line number ]


      head <File_name>                                    [ display First 10 lines ]

      head -n 25 <File_name>                           [ display First 25 lines ]

      head -25 <File_name> 


      tail   <File_name>                                              [ display last 10 lines ]
      tail   -25 <File_name>                                        [ display last 25 lines ]
      tail   -n 25 <File_name>
      tail   -f   <File_name>    [ it will keep on display last 10 lines ]  *********** 
                                             -f ---- file appending


      sed -n "<line_number>p" <File_name>

      sed -n "123p" devops.txt---------------------------------------------> it will print particular numer content only.


      sed -n "123,130p" devops.txt---------------------------------------> print from 123 to 130 lines.


      How to replace the content in file


      sample.txt

      red is danger color red red

      red red red red

      red red red 

      red red

      red 

      I want to replace red into blue

      • sed 's/red/blue/' sample.txt ---it will replace first word of the each line (For Temparary).
      • sed 's/red/blue/2' sample.txt ---it will replace second word of the each line.   (For Temparary)
      • sed 's/red/blue/g' sample.txt ---done    (For Temparary)
      • s------------String
      • g -----------globel
      • sed = 
      • S --- String
      • ed --- Editor
        • sed -i  's/red/blue/g' sample.txt   ******

      How to display page by page /screen by screen

      • more <File_name> ------------------> we can print the forward only.
      • more <File_name>-------------------> we can forward and backword.
        • ctrl + f----------------> forward
        • ctrl + b---------------->backward
        • Enter-----------------> line by line

      --------------------------------------------------------------------------------------------------------------------------------------------------

      |  pipe:-

      • Pipe is a temporary momory location.
      • where we can store the one command In-put  &  give same as Out-put to other command.

      • cat <File_name> | sort 
      • cat <File_name> |sort -r
      • cat <File_name> |sort | tr [a-z] [A-Z]

      -----------------------------------------------------------------------------------------------------------------------------------------------

      grep:    *********************

      • Global Regular Expression Print

      grep <What_You_want_to_Serch >  <Where_you_want_to_serch>

      grep  reddy sample.txt

      grep -i reddy sample.txt                               -i ---- ignoring the case sentitave ]

      grep -i  'Reddy Sekhar'  sample.txt


      ===========================================================

      System Resources Commands:

      ============================================================ 

      who ---------------------------------------> How many users are loged in currently.

      who -H------------------------------------> with Heading it will display.

      w-------------------------------------------> display more information about user, 

      How many users are logedin,

      What they are doing.

      How long the server is up and running.

      display load average.(How your CPU performing). 

      0.00,            0.00, 0.00

      1st minute          5th minute         15th minute


      If it is more than cpu count it will indicate cpu utilization is very high.

      it is based on no.of core (CPU).

      How to know my ststem cpu(Core_info) infomaton.

      ----------------------------------------------------------------

      cat /proc/cpuinfo

      uptime------------------------------------->it will display when it is re-started.

      users---------------------------------------->

      whoami------------------------------------> Currently which user logedin.

      whereis <Cmd>---------------------------> print manual pages info

      whereis ls      binary file path info.

      whereis java

      whereis mkdir


      last ---------------------------------------> how many user login & how much time they spend it.

                                                                            from which ip address he loged in.



      date

      date -s "enter date here"------------------> as a root user we can set the date.


      df ------disk free---------------------------->to find how many hard disk are attached to linux system

      Each hard dist how much is accupaid.

      remain how much free space we have.

      du -h ~ -------------------------------------> user home dir how much space accupaid.

      du -sh ~-------------------------------------> it will display summery only.



      hostname -i    ------------------------------>         |

      ifconfig--------------------------------------> display IP address                   |--------------------------------------> dispaly ip address

      ip a ------------------------------------------>                                                       |                                                                   

      hostname----------------------------------->


      man ls

      man mkdir

      man cd


      whereis mkdir

      whereis ls

      whereis cd -----------------------> it will display manual pages.

      dispaly Binary path 

      info mkdir

      info ls

      info cd


      mkdir --help

      cd --help

      ls --help


      whatis ls

      whatis mkdir

      whatis cd------------------------> Short discription.

      -----------------------------------------------------------------------------------------------------------------------------------

      How to find services on your system:

      ---------------------------------------------


      services.msc----------------------> display all running services on windows machine

      syatemctl list-unit-files--------> For linux


      systax:   service <Service_name> <Options> 

      --------                             <stop>

                             <status>

                                                                     <restart>

                                                                     <start>

      service sshd status

      service sshd start

      service sshd stop

      service sshd restart

      systemctl  <Option> <Service_name>

      systemctl start sshd.service

      systemctl stop sshd

      systemctl status sshd

      systemctl restart sshd

      --------------------------------------------------------------------------------------------------------------------------------


      ===========================================================

      Process Management  Commands

      ============================================================ 


      ps -----------------------------> display current user process id information

      ps -ef | grep java--------- -> display java process only

      ps -ef | grep jenkins

      ps -ef -------------------------> all the  user process id  information.        (system user information also it will display)

                  e--------->  all

                  f---------> formated way


       ----------------------------------------------------------------------------------------------------------------------------------------------

      Kill Command:

      ------------------

                -1

                -2

                -3

      kill    -4  <Process_ID>

                -5

                -6

                -64


      ----------------------------------------------------------------------------------------------------------------------------------------------

      Archive /Data Backup Commands

      --------------------------------------------


      zip -r devops.zip DevOps/----------------------------> Create a zip file.

      unzip <zip_file_name>

      unzip <zip_file_name> -d  /temp/------------------> where you wan to extract  (Specfic location)


      tar -cvf devops.txt   DevOps/--------------------------> Create a tar file.

      tar -xvf devops.txt

       

      useradd <User_Name>

      shadow--------------------. password information will be saved here.

      passwd

      group


      #passwd root

      #passwd ec2-user

      #passwd ramadevi


      Set attributes for your passwd

      ---------------------------------------

      chage <User_name>


      Create a group

      -------------------


      Comments

      Popular posts from this blog

      AWS

      kubernetes