0% found this document useful (0 votes)
39 views

Unix Commands: Arivezhil Narayana Miracle Software Systems

This document provides an overview of basic Unix commands including echo, ls, wc, cp, mv, rm, grep, cat, head, tail, sort, expr, tee, pipes, redirection, if/else statements, case statements, select statements, for loops, while loops, and creating simple shell scripts. It describes the basic usage and purpose of each command and control structure.

Uploaded by

Jalla Ravi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Unix Commands: Arivezhil Narayana Miracle Software Systems

This document provides an overview of basic Unix commands including echo, ls, wc, cp, mv, rm, grep, cat, head, tail, sort, expr, tee, pipes, redirection, if/else statements, case statements, select statements, for loops, while loops, and creating simple shell scripts. It describes the basic usage and purpose of each command and control structure.

Uploaded by

Jalla Ravi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 13

Unix Commands

Arivezhil Narayana Miracle Software Systems

Basic Commands

echo "some text" ls wc -l wc -w wc -c cp sourcefile destinationfile mv oldname newname rm file

Basic Commands

grep 'pattern' file cat file.txt

grep 'searchstring' file.txt

file somefile
head file tail head read var sort file.txt

what type of file

expr
tee

expr 2 "+" 3
somecommand | tee outfile

Pipes

pipes (|) send the output (stdout) of one program to the input (stdin) of another program. grep "hello" file.txt | wc -l

REDIRECTION

Redirection: writes the output of a command to a file or appends data to a file > writes output to a file and overwrites the old file in case it exists >> appends data to a file (or creates a new one if it doesn't exist already but it never overwrites anything).

Control Structure

if ....; then .... elif ....; then .... else .... fi

If else

#!/bin/sh if [ "$SHELL" = "/bin/bash" ]; then echo "your login shell is the bash (bourne again shell)" else

echo "your login shell is not bash but $SHELL"


fi

Operators

Relational -eq -ne -gt -lt -ge -le Logical -a -o !

$ cat CheckIt

Case

echo 1.Add Items


echo 2.Delete Items echo 3.Update Stock

echo Enter your choice


read mychoice case $mychoice in 1) echo The choice is Add Items ;; 2)echo The choice is Delete Items;;

3)echo The choice is Update Items;;


*) echo The choice is not a valid choice;; esac

Select

echo "What is your favourite OS?" select var in "Linux" "Gnu Hurd" "Free BSD" "Other"; do

break
done echo "You have selected $var"

What is your favourite OS?


1) Linux 2) Gnu Hurd

3) Free BSD
4) Other #? 1 You have selected Linux

#!/bin/bash colour1="red"

For loop

colour2="light blue" colour3="dark green" for X in "$colour1" $colour2" $colour3" do

echo $X
done

While loop

X=0 while [ $X -le 20 ] do echo $X X=$((X+1)) done

vi MyFistSC # assign a value: a="hello world" # now print the content of "a": echo "A is:" echo $a Save the above code and change it into execution mode

Shell Script

chmod 700 MyFirstSC Run the script as MyFirstSC or source MyFirstSC (No need to set permission)

You might also like