You are on page 1of 36

UNIX System Programming

Compiled by:
Under guidance of – Preeti Vatnani
Prof. Niranjan Shrivastava Pushpendra Patel
Preeti Soni

5-12-2010
What is UNIX :
UNIX is an operating system.

An operating system is the program that


controls all the other parts of a computer
system, both the hardware and the software.
It allocates the computer's resources and
schedules tasks. It allows you to make use of
the facilities provided by the system. Every
computer requires an operating system.

5-12-2010
What is LINUX :

Linux is a free Unix-type operating system


originally created by Linus Torvalds with
the assistance of developers around the
world. Developed under the GNU General
Public License , the source code for Linux
is freely available to everyone. The
commands & functions of linux are similar
to unix.

5-12-2010
5-12-2010
5-12-2010
Features of UNIX :
•UNIX is a multi-user, multi-tasking operating
system. Multiple users may have multiple tasks
running simultaneously. This is very different than
PC operating systems.
•UNIX is a machine independent operating system.
Not specific to just one type of computer hardware.
Designed from the beginning to be independent of
the computer hardware.
•UNIX is a software development environment. Was
born in and designed to function within this type of
environment.
5-12-2010
The shell
The shell acts as an interface between the user and
the kernel. When a user logs in, the login program
checks the username and password, and then starts
another program called the shell. The shell is a
command line interpreter (CLI). It interprets the
commands the user types in and arranges for them to
be carried out. The commands are themselves
programs: when they terminate, the shell gives the
user another prompt (% on our systems).

5-12-2010
Basic UNIX Commands

5-12-2010
Topics
 Handling Files and Directories
 Text Editors
 Compiling and Linking
 Handling Processes
 Archiving and Compressing Files
 Other Useful Commands

5-12-2010
Handling Files and Directories
 ls : list files
 cp : copy files
 mv : move files
 rm : remove files
 mkdir : make directories
 cd : change directories
 rmdir : remove directories
 pwd : print working directory
 chmod : change permission mode

5-12-2010
ls command
 Syntax
 ls [-Options] [name ...]

 Description
 Lists contents of directory.

 Frequently Used Options


 -a List all entries, including . and ..
 -d Do not list contents of directories
 -l Long listing
 -F Mark directories with a '/', etc.
 Examples
 ls -alF

5-12-2010
cp command
 Syntax
 cp [-Options] file1 [file2 ...] target

 Description
 File1 is copied to target.

 Frequently Used Options


 -f Force remove existing file
 -i Ask before removing existing file
 -r Copy directory trees
 Examples
 cp p1.c p2.c

 cp p1.c p2.c mydir

5-12-2010
mv command
 Syntax
 mv [-Options] file1 [file2 ...] target

 Description
 File1 is moved to target.

 Frequently Used Options


 -f Removes existing files without prompting the user

 -i Asks before removing existing file

 Examples
 mv p*.c mydir

5-12-2010
rm command
 Syntax
 rm [-f] [-i] file . . .

 rm -r [-f] [-i] dirname . . . [file . . .]

 Description
 Removes files or directories.

 Frequently Used Options


 -f Removal of files without prompting the user
 -i Interactive removal
 -r Recursive removal
 Examples
 rm -f p*.o

 rm -r mydir

5-12-2010
mkdir command
 Syntax
 mkdir [-m mode] [-p] dirname . . .

 Description
 Creates the specified directories.

 Options
 -m Specifies the mode to be used
 -p Create missing intermediate directories
 Examples
 mkdir -m 700 letter

 mkdir abc

 mkdir -p ./abc/def/ghi

5-12-2010
cd command
 Syntax
 cd [directory]

 Description
 Change working directory.

 If directory is not specified, the value of shell


parameter $HOME is used as the new working
directory.
 Examples
 cd

 cd ./abc/def/ghi

 cd ..

5-12-2010
rmdir command
 Syntax
 rmdir [-p] [-s] dirname . . .

 Description
 Removes directories.

 Options
 -p Remove the directory dirname and its parent
directories which become empty.
 -s Suppress the message when –p is in effect
 Examples
 rmdir letter

5-12-2010
pwd command
 Syntax
 pwd

 Description
 Prints the path name of the working (current) directory.

 Examples
 pwd

5-12-2010
chmod command
 Syntax
 chmod [-R] mode file ...

 chmod [-R] [ugoa]{+|-|=}[rwxXstl] file ...

 Description
 Changes the permissions mode of a file or directory.

 Examples
 chmod 444 file1

 chmod ugo+rw p*.c

 chmod 700 mydir

5-12-2010
Handling Processes
 ps : Prints information about active processes
 kill : Sends a signal to a process

5-12-2010
ps command
 Syntax
 ps [-Options]

 Description
 Prints information about active processes.

 Frequently Used Options


 -A Every process now running
 -e Same as -A
 -f Full listing
 -l Long listing
 Examples
 ps -ef

5-12-2010
kill command
 Syntax
 kill [-signal] pid . . .

 kill –l (the letter ‘L’ in lowercase)

 Description
 Sends a signal to the specified processes.

 The value of signal may be numeric or symbolic.

 Signal 15 is the default signal.

 kill –l lists the defined signals.

 Examples
 kill 389

 kill –3 401 402

 kill -HUP 99999

5-12-2010
Other Useful Commands
 grep : search files for a pattern
 man : on-line reference manuals
 wc : word, line and byte or character count

5-12-2010
grep command - I
 Syntax
 grep [-E| -F] pattern_list [file . . .]
 Description
 Searches the input files, selecting lines matching one or

more patterns
 Frequently Used Options
 -i Case-insensitive search
 -l Write file names only
 -n Display line number

5-12-2010
grep command - II
 Examples
 grep -i unix p1.c
 grep -n UNIX *.c *.h

5-12-2010
man command
 Syntax
 man [-Options] [-M path] [-T macropackage] [ -s section] name ...
 man [-M path] -k keyword ...
 Description
 On-line reference manuals

 Frequently Used Sections


 1 User commands and application programs
 2 System calls
 3 Library functions
 Examples
 man -s 1 mkdir
 man mkdir
 man -k pipe

5-12-2010
wc command
 Syntax
 wc [ file . . . ]

 Description
 Counts lines, words, and characters

 Options
 -c Count the number of bytes
 -m Count the number of characters
 -l Count the number of newline characters
 -w Count the number of words
 Examples
 wc -l *.h *.c

5-12-2010
date
 Guess what :-)
 Displays dates in various formats
 % date
 % date -u
 in GMT

 % man date

5-12-2010
cal

 Calendar  % cal current month


 % cal 2 2000 Feb 2000, leap year
 for month  % cal 2 2100 not a leap year
 entire year  % cal 2 2400 leap year
 Years range: 1 - 9999  % cal 9 1752 11 days skipped
 % cal 0 error
 No year 0  % cal 2002 whole year
 Calendar was
corrected in 1752 -
removed 11 days

5-12-2010
clear
 Clears the screen
 There’s an alias for it: Ctrl+L
 Example sequence:
 % cal

 % clear

 % cal

 Ctrl+L

5-12-2010
sleep
 “Sleeping” is doing nothing for some time.
 Usually used for delays in shell scripts.
 % sleep 2 2 seconds pause

5-12-2010
Command Grouping
 Semicolon: “;”
 Often grouping acts as if it were a single command, so an
output of different commands can be redirected to a file:
 % (date; cal; date) > out.txt

5-12-2010
history
 Display a history of  % !n
recently used commands  repeat command n in the
 % history history
 all commands in the history
 % !-1
 % history 10
 repeat last command = !!
 last 10
 % !-2
 % history -r 10
 repeat second last command
 reverse order
 % !ca
 % !!
 repeat last command that
begins with ‘ca’
 repeat last command

5-12-2010
exit / logout
 Exit from your login session.
 % exit
 % logout

5-12-2010
shutdown
 Causes system to shutdown or reboot cleanly.
 May require superuser privileges
 % shutdown -h now - stop
 % shutdown -r now - reboot

5-12-2010
 THANK YOU

5-12-2010

You might also like