Linux Shell Scripts and Shell Commands✌️

NazmulHyderNeshat 310 views 14 slides Nov 03, 2017
Slide 1
Slide 1 of 14
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14

About This Presentation

I just shortly describe some Linux shell script and shell commands.Hopefully, it will help you to file edit, make, delete directory operations, grep, pipeline and lots of stuff to your Linux/Mac terminal.


Slide Content

Shell Commands and Shell Scripts Presented By: Nazmul Hyder ID- 011 131 085

Shell Command Identity and Manual Command Description $uame Linux will tell you his name to you $whoami If you want to know your name $man uname For each command manual

Continue.. Editors Command Description $ kwrite File write $gedit File Edit $vi

Continue.. File Listing Command Description $ls -a Do not hide entries starting with. $ls -h Print size in human readable format $ls -l Use a long listing format $ls -s Sort by file size

Continue.. Directory Operations Command Description $pwd If u want to see your current directory $cd “directory name” To change the directory $mkdir “directory name” Create a new directory $rmdir “directory name” Remove an empty directory $rmdir -r “directory name” Remove directory with file

Continue.. File Operations Command Description $cp “file” “copyfile.txt” Copy file $rm “file.txt” To remove file $mv “file.txt “ “directory name” Create a new directory $file -i “file name” To know the file type $file -v “file name” Print the version of the file $cat “file1” “file2” To concat files and print on the standard output

Continue.. File Viewing Command Description $echo “some text” You can a line of text in the shell $more file.txt It uses for the Spacebar and the B key for the forward and backward navigation $less “file.txt” Less allows forward and backward movement using arrow keys $head filename To see the first 10 contents of the file $tail filename To see the last 10 contents of the file

Continue.. File Viewing Command Description $filename -n To print the line number of the file $sort file1 file2 To write the sorted concatenation of all the file and standard output $wc filename Print bytes,words,total lines $wc -l or -w You can see specific

Continue.. Piping and Grep Command Description $head -10 a.txt | tail -5 To see 5-10 number lines of a file $grep “a” file.txt Print lines which contains “a” $grep -i For case insensitive search $grep -c Count total matches $grep -n Display the line number of matches

Continue.. Grep Command Description $grep -E [^F] filename Anything except capital F $grep -E [$a] filename Anything that ends with a $grep -E [a-zA-Z] filename Anything that contains small a to z and capital A to Z

Shell Script Advantage of shell script : It take input from user , file and output them on screen. Useful to create own commands. Save time.

Continue.. Write and Execute : We can use any editor to write the shell script. The extension is .sh Two thing you can need to do before execute file Chmod +x script_name “set execute permission for your script” ./script_name “execute script”

Continue.. Shell Script Examples A rithmetic if-else Case #!/bin/bash expr 1 + 1 expr 1 ‐1 expr 1 \* 1 expr 1 / 1 var=`expr 1 + 1` x=1 x=`expr $x + 1` #!/bin/bash echo "Enter first number " read num1 echo "Enter second number" read num2 if [ $num1 ‐gt $num2 ] ; then echo "$num1 is greater than $num2" elif [ $num1 ‐lt $num2 ] ; then echo "$num1 is less than $num2" else echo "$num1 and $num2 are equal" fi #!/bin/sh echo “Is it morning? Please answer yes or no” read timeofday case “$timeofday” in yes) echo “Good Morning”;; no ) echo “Good Afternoon”;; y ) echo “Good Morning”;; n ) echo “Good Afternoon”;; * ) echo “Sorry, answer not recognized”;; esac

Thank You