presentation for unix commands
TRANSCRIPT
-
8/8/2019 Presentation for Unix Commands
1/36
UNIX System ProgrammingUNIX System Programming
Under guidance of
Prof. Niranjan Shrivastava
5-12-2010
Compiled by:Preeti VatnaniPushpendra PatelPreeti Soni
-
8/8/2019 Presentation for Unix Commands
2/36
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 andschedules tasks. It allows you to make use ofthe facilities provided by the system. Everycomputer requires an operating system.
WhatWhat isis UNIXUNIX ::
5-12-2010
-
8/8/2019 Presentation for Unix Commands
3/36
What is LINUX :What is LINUX :
Linux is a free UnixLinux is a free Unix--type operating systemtype operating systemoriginally created byoriginally created by LinusLinus TorvaldsTorvalds withwith
the assistance of developers around thethe assistance of developers around theworld. Developed under the GNU Generalworld. Developed under the GNU GeneralPublic License , the source code for LinuxPublic License , the source code for Linuxis freely available to everyone. Theis freely available to everyone. Thecommands & functions ofcommands & functions of linuxlinux are similarare similartoto unixunix..
5-12-2010
-
8/8/2019 Presentation for Unix Commands
4/36
5-12-2010
-
8/8/2019 Presentation for Unix Commands
5/36
5-12-2010
-
8/8/2019 Presentation for Unix Commands
6/36
Features of UNIX :Features of UNIX :
UNIX is a multi-user, multi-tasking operatingsystem. Multiple users may have multiple tasksrunning simultaneously. This is very different thanPC 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. Wasborn in and designed to function within this type ofenvironment.
5-12-2010
-
8/8/2019 Presentation for Unix Commands
7/36
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 startsanother 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
-
8/8/2019 Presentation for Unix Commands
8/36
Basic UNIX Commands
5-12-2010
-
8/8/2019 Presentation for Unix Commands
9/36
Topics
Handling Files and Directories
Text Editors
Compiling and Linking Handling Processes
Archiving and Compressing Files
Other Useful Commands
5-12-2010
-
8/8/2019 Presentation for Unix Commands
10/36
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
-
8/8/2019 Presentation for Unix Commands
11/36
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
-
8/8/2019 Presentation for Unix Commands
12/36
cp command
Syntax
cp [-Options] file1 [file2 ...] target
Description
File1is 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
-
8/8/2019 Presentation for Unix Commands
13/36
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
-
8/8/2019 Presentation for Unix Commands
14/36
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
-
8/8/2019 Presentation for Unix Commands
15/36
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
-
8/8/2019 Presentation for Unix Commands
16/36
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
-
8/8/2019 Presentation for Unix Commands
17/36
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 whenp is in effect Examples
rmdir letter
5-12-2010
-
8/8/2019 Presentation for Unix Commands
18/36
pwd command
Syntax
pwd
Description
Prints the path name of the working (current) directory. Examples
pwd
5-12-2010
-
8/8/2019 Presentation for Unix Commands
19/36
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
-
8/8/2019 Presentation for Unix Commands
20/36
Handling Processes
ps : Prints information about active processes
kill :Sends a signal to a process
5-12-2010
-
8/8/2019 Presentation for Unix Commands
21/36
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
-
8/8/2019 Presentation for Unix Commands
22/36
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 15is the default signal.
kill l lists the defined signals.
Examples
kill 389
kill 3 401 402
kill -HUP 99999
5-12-2010
-
8/8/2019 Presentation for Unix Commands
23/36
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
-
8/8/2019 Presentation for Unix Commands
24/36
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
-
8/8/2019 Presentation for Unix Commands
25/36
grep command - II
Examples
grep -i unix p1.c
grep -n UNIX *.c *.h
5-12-2010
-
8/8/2019 Presentation for Unix Commands
26/36
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
-
8/8/2019 Presentation for Unix Commands
27/36
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
-
8/8/2019 Presentation for Unix Commands
28/36
5-12-2010
date
Guess what :-)
Displays dates in various formats
% date
% date -u in GMT
% man date
-
8/8/2019 Presentation for Unix Commands
29/36
cal
Calendar
for month
entire year
Years range:1- 9999
No year0
Calendar wascorrected in 1752-
removed 11 days
% cal current month
% cal 2 2000 Feb 2000, leap year
% cal 2 2100 not a leap year
% cal 2 2400 leap year
% cal 9 1752 11 days skipped
% cal 0 error
% cal 2002 whole year
5-12-2010
-
8/8/2019 Presentation for Unix Commands
30/36
5-12-2010
clear
Clears the screen
Theres an alias for it: Ctrl+L
Example sequence:
% cal % clear
% cal
Ctrl+L
-
8/8/2019 Presentation for Unix Commands
31/36
5-12-2010
sleep
Sleeping is doing nothing for some time.
Usually used for delays in shell scripts.
% sleep 2 2 seconds pause
-
8/8/2019 Presentation for Unix Commands
32/36
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
-
8/8/2019 Presentation for Unix Commands
33/36
5-12-2010
history
Display a history of
recently used commands
% history
all commands in the history
% history 10
last 10
% history -r 10
reverse order
% !!
repeat last command
% !n
repeat command n in the
history
% !-1
repeat last command = !!
% !-2
repeat second last command
% !ca
repeat last command thatbegins with ca
-
8/8/2019 Presentation for Unix Commands
34/36
5-12-2010
exit / logout
Exit from your login session.
% exit
% logout
-
8/8/2019 Presentation for Unix Commands
35/36
5-12-2010
shutdown
Causes system to shutdown or reboot cleanly.
May require superuser privileges
% shutdown -h now - stop
% shutdown -r now-
reboot
-
8/8/2019 Presentation for Unix Commands
36/36
THANK
YOU5-12-2010