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

RTOS7

The document provides an overview of programming in Linux, including its history and features. It describes Linux commands for file manipulation, directories, input/output redirection, pipes and filters. It also covers file protections, process commands, and the shell.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

RTOS7

The document provides an overview of programming in Linux, including its history and features. It describes Linux commands for file manipulation, directories, input/output redirection, pipes and filters. It also covers file protections, process commands, and the shell.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

UNIT - 7

PROGRAMMING IN
LINUX

P.V.K.Chaitanya, E.C.E, GVPCEW

OVERVIEW

UNIX was developed by Ken Thomson and


Dennis Ritche.

It became popular in
commercialized in 1981

Most of the OS was developed in C Language,


only a very little code is written in processor
specific assembly language.

It provides a large number of utilities for


software development like editors, compilers,
debuggers and a powerful user interface, the
shell.

P.V.K.Chaitanya, E.C.E, GVPCEW

1970s

and

was

OVERVIEW

A number of Unix flavours are available, such as


AT&T Unix, HP UX, Sun Solaris, IBM AIX, Ultrix
and Linux.

Linux developed by Linus Trovalds, is a freely


distributed implementation of Unix like Kernel.

Even the source code for Linux is freely


available.

Programming in Linux is same as programming in


Unix

P.V.K.Chaitanya, E.C.E, GVPCEW

FEATURES OF LINUX

Multi-user operating system


File system is organized hierarchically.
Top

most is the root directory denoted by /


Other important directories are

/bin
/usr/bin
/etc
/dev
/usr/spool/mail
/usr

Number of user interfaces.


Command

user interfaces like shell(sh), kshell(ksh),

cshell(csh)
X Windows provides Graphical User Interface
P.V.K.Chaitanya, E.C.E, GVPCEW

FEATURES OF LINUX

All devices are treated as files. /dev directory


contains one entry for each file.

To provide security for users files, every user


will have a password. Only encrypted password
is stored in the system. The file /etc/passwd
contains list of all authorized users and the
encrypted passwords

Every file is given protections- read, write and


execute permissions are given to users, groups
and others. The owner of the file can give
permissions.

P.V.K.Chaitanya, E.C.E, GVPCEW

LINUX COMMAND SUMMARY

$ sign is the system prompt which indicates


that the system is ready to take commands.
Format

is

$ commandName Options Arguments


banner

To display a banner

cal

To display calender for a month or year

date

To display todays date

sleep

To make the shell sleep for few seconds

who am i

To know about your login details

who

To display list of users who are presently logged in

clear

To clear the screen

passwd

To change the password

echo

To echo a string
P.V.K.Chaitanya, E.C.E, GVPCEW

FILE MANIPULATION COMMANDS


ls

To see files in the directory

ls l

Displays details of files such as permisions, size, date,..

ls a

To list hidden files

cat

To display contents of one or more files

cp

Copy file1 to file1

rm

To delete a file

rm i

To delete a file, ask for confirmation before deletion

mv

To rename a file

head

To display top 10 lines of a file

tail

To display bottom 10 lines of a file

spell

To check spelling of words in a file

wc

To display number of lines, words and characters in a file

wc w

To display number of words in a file

wc l

To display number of lines in a file

wc c

To display number of characters in a file

nl

To display a file with line numbers


P.V.K.Chaitanya, E.C.E, GVPCEW

DIRECTORY COMMANDS
pwd

To know the present working directory

cd

To change the directory

mkdir

To create a new directory

rmdir

To delete a directory ( only when it is empty )

find

To search for a file

du

To know the directory size in number of blocks

df

To know the disk space occupied by the total file system


and the amount of disk space which is free

P.V.K.Chaitanya, E.C.E, GVPCEW

INPUT / OUTPUT REDIRECTION

In LINUX all the devices are considered as files. Hence there


are three standard files
stdin stdout stderr

$ls l > filelist

$cat file2 > file1

File2 is appended to fie1

$wc <filename

Contents of file1 are overwritten with contents of file2

$cat file2 >> file1

The contents of the directory are redirected to the file filelist


instead of displaying on the monitor.

Word/line/character count is done on the file filename

$wc < file1 > file2

Word/line/chatacter count is done on file1 and counts are stored in


file2.
P.V.K.Chaitanya, E.C.E, GVPCEW

PIPES AND FILTERS

Pipes are used to pass output of one command


to another command
$cat

hello.c | more

Output of cat command is passed to more command which


displays few lines at a time

$more

hello.c

more is a filter that processes the input data to display


a few lines at a time.

Some important filters


sort
grep
tr

sorting utility
pattern matching utility

translation utility
P.V.K.Chaitanya, E.C.E, GVPCEW

PIPES AND FILTERS

$ ls | sort

$ ls | sort r

Sorts the numbers in a file

$ grep how filename

To sort contents of a directory in reverse alphabetical order

$ sort n filename

To sort the contents of a directory

Displays all the lines in a file which contains the string how

$ cat filename | grep how

$ tr [:upper:] [:lower:] < file1 > file2

Converts all upper case letters to lower case and produces file2.

$ tr s [ ] [\012] < temp > temp0

Repalces each space in temp with a new line and will keep it in a file
temp0.
P.V.K.Chaitanya, E.C.E, GVPCEW

PIPES AND FILTERS

$who > log

$who | wc l

$who | sort

$who | grep prasad

$<etc/passwd | wc l

$date; who | wc l > log

$tr s [ ] [\012] < file | grep ^. | sort |


uniq c > fours

$sort temp2 > temp3

$uniq c temp3 > output


P.V.K.Chaitanya, E.C.E, GVPCEW

FILE PROTECTIONS

Each file will be owned by a user. The owner can assign read,
write and execute permissions to his file, to the group
members or to others.

The command $ls l displays the first field in each line in the
format drwxrwxrwx.

If we want to give read, write and execute permissions to


everyone, the command is
$ chmod 777 filename

Alternately we can change permissions as


$ chmod w filename
$ chmod +x filename

$ chown username filename

To change ownership of a file

$ chgrp groupname filename

To change group ownership of a file


P.V.K.Chaitanya, E.C.E, GVPCEW

PROCESS COMMANDS

When we login, a process is created which is a


shell.

When a shell command is given, the shell creates


another process.

Shell process is the parent and command process


is the child.

Each process will be given a PID and PPID.

$ ps ef
Gives

the various processes running

Foreground and background processing


$

cat filename > /dev/lp0

cat filename > /dev/lp0 &


P.V.K.Chaitanya, E.C.E, GVPCEW

PROCESS COMMANDS

$ kill -9 <pid>
To terminate

$ time <command>
To find

a running process

the time taken by a process to execute

Each process will have priority. A higher priority


process will get CPU time more frequently.
$nice

10 ./a.out > filename

P.V.K.Chaitanya, E.C.E, GVPCEW

SHELL

Shell provides an interface to the user of the


operating system.

Procedure for command line interpretation

Shell waits for the user to enter a command

When the user enters a command, shell reads the


command, analyzes and checks for syntax error. If no
errors, the command is broken into words.

First word is taken as command and the rest are taken as


arguments.

Shell creates a child process. This operation is called


fork. Child process executes the command using
exec command and the parent process waits for the
child to complete.

Parent process issues a new prompt for the next


command.
P.V.K.Chaitanya, E.C.E, GVPCEW

You might also like