Day - 3 of internship at Aartronix

19) grep :  it is used to find pattern/string in files

examples:-

grep Name sample.txt
grep -v Name sample.txt
grep -n Name sample.txt grep -c Name sample.txt
grep -i name sample.txt
grep Name sample1.txt sample2.txt
echo grep -i error *.log
grep 5 sample.txt
grep -v 5 sample.txt
grep -r grep ~/Documents
grep -ri Error ~/Documents

  • our sample.txt file:

MARKSHEET - Class 10A

| Roll No | Student Name | Math | English | Science | History | Total | Grade |

|---------|--------------|------|---------|---------|---------|-------|-------|

|    1    |  Aman Kumar  |  85  |    78   |    88   |   82    |  333  |   A   |

|    2    | Priya Sharma |  92  |    85   |    90   |   88    |  355  |   A+  |

|    3    | Rahul Singh  |  78  |    72   |    80   |   75    |  305  |   B   |

|    4    |  Neha Patel  |  88  |    90   |    86   |   91    |  355  |   A+  |

|    5    | Vikram Gupta |  75  |    68   |    72   |   70    |  285  |   B-  |

|    6    | Anjali Verma |  95  |    92   |    94   |   89    |  370  |   A+  |

|    7    |  Rohan Desai |  82  |    80   |    81   |   79    |  322  |   A   |

|    8    |   Zara Khan  |  90  |    88   |    89   |   87    |  354  |   A+  |



    25) ls :- to list files and directories in current directory

        -l ---> shows permissions and other details

    26) pwd : prints working directory
    
    27) cd : - change directory 
    
    28) mkdir :- make directory ; mkdir name_of_dir
  • For multiple directory 
    • mkdir dir1 dir2 dir3 (here dir can be replaced by any string)
    • mkdir dir{1,2,3}
    • mkdir {1,2,3}dir
    • mkdir dir{1..7}
    29) rmdir :- remove empty directory ; rmdir name_of_dir
  • For multiple directory 
    • rmdir dir1 dir2 dir3 (here dir can be replaced by any string)
    • rmdir dir{1,2,3}
    • rmdir {1,2,3}dir
    • rmdir dir{1..7}
    30) cp/mv :-  copy/move ; cp/mv <from_file>  <to_file>
  • can be used on multiple files:
    • mv/cp file{1..8} file{1..8}.txt
    31) rm :- remove file; rm [options]  <file>
  • to remove directories completely use -r 
  • using -i , it would ask before removing any file or directory everytime.
  32)touch:- The touch command in Linux creates an empty file or updates the timestamp of an existing file. 

  33)clear :- it clears the console/terminal.

 

Scripting:

  1. Script to make directory and files.
    • banner DIRECTORY MAKER SCRIPT
      echo Starting directory creation script...
      i=1
      ls
      while
      [ $i -lt 5 ]
      do
      echo creating dir$i
      mkdir dir$i
      cd dir$i
      echo This is file in directory $i. > file$i.txt
      cd ..
      ((i++))
      done
      ls
      echo script execution completed
  2. Script To make and remove directory  but preserve file.
    • banner DIRECTORY REMOVER SCRIPT
      echo Starting directory remover script...
      i=1
      ls
      while
      [ $i -lt 5 ]
      do
      cd dir$i
      echo Moving files in directory$i.
      mv * ~/Documents/Scripts/
      cd ..
      echo Removing dir $i.
      rm -r dir$i
      ((i++))
      done
      ls
      echo script execution completed

SHELL

  • The Shell -  To  communicate and work with kernel user needs an interface that can be graphical or text based.
    • The Shell Families
      • Bourne Shell
      • Korn Shell(Ksh)
      • Csh & TCsh
      • COMMAND.COM(MS-DOS)
    • All Shell follow same 4 steps process:
      • Read a command line.
      • Parse and interpret it.
      • Invoke the execution of the command line.
      • Go to step 1.
  • Shell Prompt
    • ways to get shell access:
      • Terminal - By running terminal.
      • SSH - By logging in into remote server.
      • Console - By logging into system.
    • some useful commands to know about your shell:
      • echo $SHELL
      • cat /etc/shells
      • $env
  • Environment Variables
    • $HOME - 
    • $IFS
    • $LANG
    • $MAIL
    • $PATH
    • $PS1
    • $PS2
    • $SHELL
    • $TERM
  • Shell Scripting
    • Well generally we give command to shell and it takes it to kernel but what if we want to this process, we use shell scripting, Shell Script is a text file containing commands we run in a shell environment. 
  • Why shell Scripting
    • Creating your own power tools/utilities.
    • Automating Command input and output.
    • Customizing administrative tasks.(Well you don't enjoy write same commands do you, do you?)
    • Creating simple applications.
  • The bash shell - The bourne Again shell.
    • It have two types of commands:
      • internal - inbuilt commands.
      • external - imported binary libraries stored in /bin
  • The shell programming environment
    • Two ways to make shell scripts:
      • use #! /bin/sh as first line of shell script.
      • use sh -f filename.sh command after writing script.
  • Shebang - It is the line which indicates an interpreter to execute the shell script.
  • Shell comments - They are comments like in any programming language and start with "#".

Comments

Popular posts from this blog

Day - 1 of internship at Aartronix