Wednesday, August 17, 2022

Linux.....!

 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/release

Basic Commands

mkdir <dir_name> ------------> empty dir only

mkdir -v <dir_name>                                        (-v -----Verbos)----(display a message)..     

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

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








                             Udemy  - Linux

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

      class : 01 [Introduction]

      class : 03 [ How to open and close Terminal ]

       Window ----ctrl + alt + t--------Open

                                      ctrl  +  d-----------close

      class : 04 [ Our First Commands ]

      sudo apt -y install ncal ----------------------------------> Install cal package.

      • echo Hello
      • echo echooooooooooooo
      • cal
      • cal 2022 ( cal -y )------------------------> 
      • date 
      • Clear      ( ctrl + l )----------------------->
      •  history
      •  !12     ------------------------------------->
      • !!                              
      •  history -c; history -w
      •  exit / ctrl + d

      class : 05 [ Understanding Command Structure ]

      • echo $PATH
      • which cal
      • which echo
      • which which
      • cal
      • cal  2017
      • cal 12 2017
      • cal  -y ----------------------------------------------->display current year
      • date 
      • date -u   ( date --universal)----------------------->Universal time
                • date -abcdef
                • date --longform1 --longform2 --longform3

      Command = CommandName    -Options    Inputs 

        • cal 12 2017
              • cal -A 1 12 2017
              • |       |      |____________Inputs
              • |       |_________Options
              • |_____ CommandName
        • cal -B 1 12 2017
        • cal -A 1 -B 1 12 2017
        • cal -A =1 -B=1 12 2017   
        • cal --after =1 --before=1 12 2017

      class : 06  [ Using the Linux Manual - Part 1 - The Manual's Structure ]

      Section           Contians

      1 User Commands
      2 System Cells
      3 C Library Functions
      4 Device and Special Files
      5 File Formats and Conventions
      6 Games
      7 Miscellaneous
      8 System Administration

      class : 07  [ Using the Linux Manual - Part 2 - Reading the Man Pages ]

      •  man -k which                                        [ -k    Search]
      • man 1 which
      • man 6 sol
      • man which
      • man lcf
      • which date cal
      • which [ -a ] <Something> ...
      • which [ -a | -f ] <Something> ...

      class : 08  [ Using the Linux Manual - Part 3 - Putting it all together ]

      • man -k "list directory content"
      • man ls
      • ls -l
      • ls -h
      • help cd / man cd
      • man pwd / help pwd
      • help



        class : 01

        class : 01

        class : 01

        class : 01

        class : 01

        class : 01

        class : 01

        class : 01

        class : 01

        class : 01

        class : 01

        class : 01

        class : 01

        class : 01

        class : 01

        class : 01

        class : 01

        class : 01

        class : 01

        class : 01

        class : 01

        class : 01

        class : 01

        class : 01

        class : 01

        class : 01

        class : 01

        class : 01



















                      


































        User / Group Administration Commands

        Useradd: Creates a new User account.
                                After creating a user 3 dire will create automatically.
                                /etc/passwd
                                        shadow
                                        group

        passwd:  Changs a User's Password.
            passwd ramadevi
            passwd ec2-user
            passwd root
                            password information saved in shadow dir
        passwd
        chage ramadevi

        Create a group:
        to manage the users..........!


        groupadd <Group_Name>

        groupadd devops

        usermod -g <Group_Name> <User_Name>

        How to check a  user belongs to how many groups ?

                id    <User_Name>
            groups <user_Name>
        id ec2-user
        id ramadevi


        how to check a particular group how many users are there ?

        lid -g <Group_Name>
        lid -g devops

        su-----------------------> Switch user

        Normal_User---------Normal_User---------->passwd
        Normal_User---------Root_User-------------->passwd

        Root_user--------Normal_User---------->no passwd required


        su - ramadevi---------Best practic
        su ramadevi

        su - root
        su -


        give sudo access
        ------------------------

        vi /etc/sudoers

        visudo--------Best practic
        ramadevi

        useradd ramadevi
        sudo useradd ramadevi
        ls -l /home


        userdel <User_Name>
        userdel -r <User_Name>---------------> if you want to delete user dir also  from home dire
        groupdel <Group_Name>


        Remote Access Commands:

        How to connect to the server ?
        with help of IP address/Host name
                            UN
                             Passwd


        ssh un@ip
        passwd

        ssh   ramadevi@IP
        passwd

               ssh/sshd_config
        Scp--------------Secure Copy

        Youtube -----SCP Command

        Before do make sure passworklessauthentication yes

        in both server

        Syntax:    scp fn/dn un@ip/hn:/temp/

        scp devops ec2-user@159.28.1.1:/temp/



        Want to check Ram size in server

        free
        free -h
        free -k
        free -m
        free -g


        to check Ram hard ware information:

        # dmidecode
        dmidecode -t 17
        dmidecode -t 15
        dmidecode -t 1
        dmidecode -t 20


              
         
        Virtual machine-----------------> typr= ram

        On premise machine ----------> type = SDRAM
                                                                        DDR1, DDR2

        Automating/Scheduling  Tasks Commands

         Crontab

        With help of crontab we can scheduling our daily jobs.
        By default this features can access all the users.


        How to restic to access the everyone ?

        • Create one empty file in /etc/
        • touch /etc/crown.all
        • add the user in cron.all file to whom you wan to give the access
        crontab -l---------------> display all jobs
        crontab -e---------------> edit existing jobs/create a new jobs
        crontab -r----------------> delete jobs
        crontab -ir
        How to see other user Crontab jobs ?
        #crontab -l -u ramadevi

        Crontab Format

        [Minute]---[Hour]---[Day of month]---[Month]------------[Day of week]---[Command/script]
        0-59              0-23         1-31                         1-12 or jan-dec         0-6 or sun-sat         /usr/bin/.sh


        How to stop crontab jobs?

        Stop mentioned service
                        crond.service


        */1 * * * * /home/ec2-user/hello.sh    >  /home/ec2-user/hello.log
        */1 * * * * /home/ec2-user/hello.sh    >  /home/ec2-user/hello.log 2>&1
        */1 * * * * /home/ec2-user/hello.sh    > > /home/ec2-user/hello.log 2>&1


        > -------------redirect std o/p
        >> -----------appaned std o/p

        File descriptors:
        -------------------

        1 ----------Stand I/p
        2 ----------Stand o/p
        3 -----------Stand error


        script
        script ramadevi.txt
        cat typescript
        script -a typrscript















































        Labels:

        0 Comments:

        Post a Comment

        Subscribe to Post Comments [Atom]

        << Home