Sei sulla pagina 1di 7

Ex1: Introduction to LINUX Commands

Aim: To study the general commands in linux to perform File operation

General Commands

Create a file : vi <filename.sh>

Running a file : sh <filename.sh>

Make a new directory : mkdir <directory name>

Change directory (or) open : cd <directory name>

Change to the parent directory : cd ..

Move a file : mv < filename1> <filename2>

Copies a file : cp < filename1> <filename2>

Removes a file : rm <filename>

Lists your file : ls

Online manual (help) about command : man ls

To work with editor the following commands are used

i - left of cursor

I - Beginning of the line

a - append text to the right of the cursor

A - append text to the end of the line

o - open the line below

O - open the line above

S - Replace single character

R - replace from the cursor to right

Saving and exit:

:w - save a file

:wq - Save and quit editing mode

:q - Quit editing when no changes are done

:q! - quit editing mode by changing to file


Ex :2 Printing date and time

Aim: to write a shell program to display the date, time, current date and user id and parent
directory

Commands:

1. Create a file vi filename.sh

2. Save a file :wq

3. Running a file: bash filename.sh

4. Echo – write argument to the standard output

Synopsis: echo [lc][string]

Description: do not print the trailing new line character.

5. Log name - Display user login name

Synopsis: logname

Description: The logname utility writes the user’s login name to standard output followed by a
new line

6. Date - Display (or) Set date and time

Synopsis: date [-dst] [ -tminutes-west]

Description: when invoked without arguments, the date utility display the current date and
time

7. Pwd - Return working directory name

Synopsis: pwd [-l1-p]

Description: the pwd utility writes the absolute pathname of the current working directory to
the standard output

8. who am i - Display effective user id

Synopsis: who am i

Description: The who am i utitlity has been obsolete by the id

The whoami utility display your effective user is as a name

Program:

echo “***** DISPLAY DATE, TIME AND USER ID *****”

usname=telnet1
echo “User Name = $usname”

echo “Current Date = $(date)”

echo “Current Directory = $(pwd)”

echo “User ID = $(who am i)”

Output:

***** DISPLAY DATE, TIME AND USER ID *****

User Name = telnet1

Current Date = Fri Aug 21 10:55:12 IST 2009

Current Directory = /home/telnet1

User ID = telnet1 pts/2 Aug 21 10:55 (192.168.21.23)

Ex.no : 3 Retrieve system Information

Aim: To write a shell program to display the system information

Commands Used:

1. Create a file vi filename.sh

2. Save a file :wq

3. Running a file sh filename.sh

4. Echo – write argument to the standard output

Synopsis: echo [lc][string]

Description: do not print the trailing new line character.

5. uname - Print operating system name

Synopsis: uname

Description:

uname –a - behaves as through all of the option

uname –v - Print Operating System version

uname –m - Print Machine hardware name


uname –n - Print node name

uname –p - Print Machine Processor Architecture name

uname –r - print opearating system release

uname –s - print operating system name

Program:

echo “SYSTEM INFORMATION”

echo “Network Name and Node Name = $(uname -n)”

echo “Kernal Name = $(uname -s)”

echo “Kernal Version = $(uname -v)”

echo “Kernal Release = $(uname -r)”

echo “Operating System = $(uname -o)”

echo “Processor Type = $(uname -p)”

echo “Machine Information = $(uname -m)”

echo “All Information = $(uname -a)”

Output:

SYSTEM INFORMATION

Network Node and Node Name = Local Host / Hostdomain

Kernal Name = Linux

Kernal Version = #1 SMP Fri Aug 21 10:55:12 EDT 2009

Kernal Release = 2.6.9-22.ELsmp

Operating System = GNU/Linux

Processor Type = x86_64

Machine Information = x86_64

All Information = Linux Local Host / Hostdomain 2.6.9-22.ELsmp #1 SMP

Fri Aug 21 10:55:12 EDT 2009 x86_64 x86_64 GNU/Linux


Ex no :4 Looping Pattern

Aim : to write a Linux programming to display the character in looping pattern

Commands:

1. Create a file vi filename.sh

2. Save a file :wq

3. Running a file sh filename.sh

4. Echo – write argument to the standard output

Synopsis: echo [lc][string]

Description: do not print the trailing new line character.

5. For - The for loop operate on lists of items.

Synopsis: for (( initialization;condition;inc/dec))

Description: It repeats a set of commands for every item in a list.

Program:

echo “Enter No.”

read n

for ((i=1;i<=$n;i++))

do

for ((j=1;j<=$i;j++))

do

echo -n “*”

done

echo “”

done

Output:
Enter No.

**

***

****

*****

Ex no :5 Looping Pattern

Aim : to write a Linux programming to display the character in looping pattern

Commands:

1. Create a file vi filename.sh

2. Save a file :wq

3. Running a file sh filename.sh

4. Echo – write argument to the standard output

Synopsis: echo [lc][string]

Description: do not print the trailing new line character.

5. for - The for loop operate on lists of items.

Synopsis: for (( initialization;condition;inc/dec))

Description: It repeats a set of commands for every item in a list.

echo “Enter No.”


read n
for ((i=1;i<=$n;i++))
do
for ((j=1;j<=$i;j++))
do
echo -n “*”
done
echo “”
done
for ((i=$n-1;i>=1;i--))
do
for ((j=1;j<=$i;j++))
do
echo -n “*”
done
echo “”
done

Output:

Enter No.
5

*
**
***
****
*****
****
***
**
*

Potrebbero piacerti anche