linuxcommands_advanced
linuxcommands_advanced
===================================================
1) pwd command
2) cal command
3) echo command
4) date command
5) tty command
6) whoami command
7) clear command
8) help option
With almost every command, ‘--help’ option shows usage summary for that command.
9) whatis command
This command gives a one line description about the command. It can be used as a quick reference for
any command.
$ cd [path-to-directory]
$ ls [files-or-directories]
$ mv source destination
$ rmdir
$ rm files|directories
The 'cat' command is actually a concatenator but can be used to view the contents of a file.
Displays the first few lines of a file. By default, the ‘head’ command displays the first 10 lines of a file.
But with -n option, the number of lines to be viewed can be specified.
Similar to ‘head’; the ‘tail’ command shows the last 10 lines by default, and -n option is available as well.
20) wc command
Word count
This command counts lines, words and letters of the input given to it.
22) VI editor
The VI stands for Visual editor; another text editor in Linux. This is a standard editor in many Linux/Unix
environments.
$ vi hello.txt
The ‘alias’ is another name for a command. If no argument is given, it shows current aliases. Aliases can
be used for short names of commands. For example, you might use the clear command frequently. You
can create an alias for it:
$ alias c="clear"
24) w command
w command is used to check which users are logged in to the system, and what command they are
executing at that particular time:
Displays information about the users who logged in and out of the system. The output of the last
command can be very large, so the following output has been filtered (through head) to display the top
10 lines only:
26) du command
The du command determines disk usage of a file. If the argument given to it is a directory, then it will list
disk usage of all the files and directories recursively under that directory:
27) df command
$ df
In Linux, you can use shutdown command to gracefully halt your system. Most commonly used
command is
shutdown -h now
================================================================
1) Simple Message print
#!/bin/bash
when you want to run the file then use below command
$ bash hello-world.sh
$ ./hello-world.sh
#!/bin/bash
#!/bin/bash
((sum=25+35))
echo $sum
4)Multi-line comments
#!/bin/bash
:'
'
((area=5*5))
echo $area
Syntax:-
while [ condition ]
do
commands 1
commands n
done
#!/bin/bash
i=0
while [ $i -le 2 ]
do
echo Number: $i
((i++))
done
#!/bin/bash
do
done
printf "\n"
7) Receive Input from User
#!/bin/bash
read something
8. The If Statement
Syntax
if CONDITION
then
STATEMENTS
fi
#!/bin/bash
read num
if [[ $num -gt 10 ]]
then
fi
#!/bin/bash
read n
if [ $n -lt 10 ];
then
else
echo "It is a two digit number"
fi
#!/bin/bash
read num
else
fi
#!/bin/bash
read n
if [[ ( $n -eq 15 || $n -eq 45 ) ]]
then
else
fi
#!/bin/bash
read num
if [[ $num -gt 10 ]]
then
then
else
fi
#!/bin/bash
read num
case $num in
100)
echo "Hundred!!" ;
200)
*)
esac
14)Concatenating Strings
#!/bin/bash
string1="Ubuntu"
string2="Pit"
string=$string1$string2
#!/bin/bash
subStr=${Str:0:20}
echo $subStr
#!/bin/bash
read x
read y
(( sum=x+y ))
#!/bin/bash
sum=0
do
read n
(( sum+=n ))
#echo -n "$counter "
done
printf "\n"
#!/bin/bash
function Add()
read x
read y
Add
#!/bin/bash
read newdir
cmd="mkdir $newdir"
eval $cmd
#!/bin/bash
if [ -d "$dir" ]
then
else
`mkdir $dir`
fi
#!/bin/bash
read name
rm -i $name
#!/bin/bash
cat editors.txt
cat editors.txt
#!/bin/bash
recipient=”[email protected]”
subject=”Greetings”
message=”Welcome to UbuntuPit”
`mail -s $subject $recipient <<< $message`
#! /bin/sh
read filename
if [ -f "$filename" ]; then
else
fi
exit 0
#!/bin/bash
read time
sleep $time
#!/bin/bash
sleep 5 &
pid=$!
kill $pid
wait $pid
#!/bin/bash