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:
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:
- Script to make directory and files.
- banner DIRECTORY MAKER SCRIPTecho Starting directory creation script...i=1lswhile[ $i -lt 5 ]doecho creating dir$imkdir dir$icd dir$iecho This is file in directory $i. > file$i.txtcd ..((i++))donelsecho script execution completed
- Script To make and remove directory but preserve file.
- banner DIRECTORY REMOVER SCRIPTecho Starting directory remover script...i=1lswhile[ $i -lt 5 ]docd dir$iecho Moving files in directory$i.mv * ~/Documents/Scripts/cd ..echo Removing dir $i.rm -r dir$i((i++))donelsecho 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 "#".
- 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.
- 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
- $HOME -
- $IFS
- $LANG
- $PATH
- $PS1
- $PS2
- $SHELL
- $TERM
- 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.
- 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.
- It have two types of commands:
- internal - inbuilt commands.
- external - imported binary libraries stored in /bin
- Two ways to make shell scripts:
- use #! /bin/sh as first line of shell script.
- use sh -f filename.sh command after writing script.
Comments
Post a Comment