Unix Commands: Arivezhil Narayana Miracle Software Systems
Unix Commands: Arivezhil Narayana Miracle Software Systems
Basic Commands
Basic Commands
file somefile
head file tail head read var sort file.txt
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 else
#!/bin/sh if [ "$SHELL" = "/bin/bash" ]; then echo "your login shell is the bash (bourne again shell)" else
Operators
$ cat CheckIt
Case
Select
echo "What is your favourite OS?" select var in "Linux" "Gnu Hurd" "Free BSD" "Other"; do
break
done echo "You have selected $var"
3) Free BSD
4) Other #? 1 You have selected Linux
#!/bin/bash colour1="red"
For loop
echo $X
done
While loop
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)