Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
!
|
|
|
^ Introduction to OS concepts
^ Introduction to Unix Operating System
^ Unix System Architecture
^ Introduction to Unix File System
^ Starting to work with UNIX
|
^ Is a System software
^ Can be defined as
^ An Organized collection of software consisting of
procedures for operating a computer
^ Provides an environment for execution of programs
^ Acts as an interface between the user and the hardware of the
computer system.
|
|
|
|
|
|
|
à
à
à
Other
application
programs
|
|
|
|
|
^ Swapping
^ Demand Paging
|
|
|
^ File system is the structure in which the files are stored in the
disk
|
|
VG i/Linux: G i, OSD/ïosix
|
^ The Owner
^ Group member
^ other users
|
^ Log in
^ Log out
|
|
^ pwd
^ Identifies the current working directory.
^ date
^ Displays the current date and time
^ who
^ Displays the names of all the users who have currently
logged in
^ who am i
^ Displays the name of the current user.
|
ls
Syntax :ls [options] [file«.]
options:-l list in long format
-a list all file including those
beginning with a dot
-i list inode no of file in first column
-s reports disk blocks occupied by file
-R recursively list all sub directories
-F mark type of each file
-C display files in columns
|
u 0 or more characters
? 1 character
[-] matches any one character between the brackets
[^ ] not matches any one character in the brackets
|
total 6
-rwxr-xr-x 1 user1 training 12373 Dec 15 14:45 a.out
drwxr-xr-x 2 user1 training 4096 Dec 22 14:00 awkpro File name
-rw-r--r-- 1 user1 training 12831 Dec 12 13:59 c
-rw------- 1 user1 training 61440 Dec 15 11:16 core
-rw-r--r-- 1 user1 training 255 Dec 20 14:29 cs
userid
Date &Time of
File access Modificaion
permission
Type
of file
|
)
*+ keyword list command synopsis line for all keyword
matches
*, path path to man pages
* show all matching man pages (SVR4)
|
|
^ File Permissions
|
^ Permission Levels
^User (owner) ()
^Group (wheel, staff, daemon, etc.) ()
^World (guest, anonymous and all other users) ()
^ Permission Settings
^Read ()
^Write (Ñ)
^Execute ()
|
|
|
Octal Number
r -4
w -2
x -1
ù chmod 744 xyz
this will set rwx for user, r± for group, r²for others
|
Example:
^mkdir project1
This creates a directory project1 under current directory
Note:
Write and execute permissions are needed for the user to create a
directory
|
|
Copying a file cp
Moving a file mv
Removing a file rm
|
Example
cp file1 file2
Note:
cp -r /dev/tty myfile
|
^ -r
Recursive copy; copy subdirectories under the directory if
any
|
group id
^
permissions
^
|
Caution: Use ³i´ option along with ³r´ to get notified on deletion
|
ùls ±l
-rwxr-xr-x 1user2 training 12373 Dec 15 14:45 a.out
-rwxr-xr-x 3 user1 faculty 4096 Dec 24 11:56 awkpro
ùls ±l
-rwxr-xr-x 1user2 training 12373 Dec 15 14:45 a.out
-rwxr-xr-x 3 user1 training 4096 Dec 24 11:56 awkpro
|
umask value is used to set the default permission of a file and directory
while creating
umask command is used to see the default mask for the file
permission
Default umask value will be set in the system environment file like
/etc/profile
umask 022 will set a mask of 022 for the current session
The file permission after setting this umask value will be 644
^
|
Linking files
|
^ Sticky bit
^ Typically set to a directory that is sharable
^ This allows individual users to create/delete their files
^ Only the owner or root has the privileges to remove any file
in the directory
|
|
|
|
|
|
Backspace Space
h j k l
w w w ù
the quick brown fox the quick brown fox
2 w ^
the quick brown fox
b b b
|
|
etc..
Redirection operators
Filters
|
|
Touch <file> will change the time of change of the file is the file
exists
|
x=10
echo ùx
10
|
more
^ Allows the user to view one page full of information at a time.
file
^ Used to display the type of the file
tty
^ Prints the terminals name
|
wc
^ A filter used to count the number of lines,words and characters
in a disk file or in the standard input.
^ -l - displays the number of lines
^ -w - displays the number of words
^ -c - displays the number of characters
|
cmp
^ Returns the offset and the line number and the line number of
the first position where the two files differs.
comm
^ col1 - unique lines of first file
^ col2 - unique lines of second file
^ col3 - common lines
|
diff
^ Indicate the differences between the files
^ a Lines added
^ d Lines deleted
^ c Lines changed
|
find
^ Used to locate a file or a directory in the given path
Usage
find <path> [options]
^
Options
name - accepts the format to searched
^
|
pr
^ Used to display a file in a format to be printed.
^ Breaks up a file into pages with a header, text and footer area
Options
-l
^ to alter the length of the file
-h
^ to set the header
-t
^ to suppress the header and the footer
|
|
ù ls ±l > outfile
|
Filters are programs that takes its input from the std i/p file,
processes it and sends it to the std o/p file.
grep
^
cut
^
head
^
tail
^
paste
^
|
Sorts the contents of the given file based on the first char of each
line.
-n --numeric sort
-r --Reverse sort
-t -Specify delimiter for fields
|
|
|
|
ù head -3 file1
|
ù tail -3 file1
Can also specify the line number from which the data has to be displayed
ù tail +5 file1
|
usage :
tr [a-z] [A-Z] filename
^
|
Example:
ù cat u | wc
|
Example
who | tee userlist
^
|
|
-d -->Specify delimiter
|
|
áà
put/send: Ôransfer to Other hosts
It will prompt for every file to be transferred, unless the -i flag was used
on the ftp command line, or the prompt command is issued.
mput is very useful when moving a number of files.
|
isage is very similar to compress and pack utilities in unix:
gzip [-vc] filename
where -v displays the compression ratio.
-c sends the compressed output to standard output and leaves the original file
intact.
6
gunzip can uncompress files originally compressed with compress.
|
tar is a utility that packs a list of files (and/or directories) into a specific tarfile,
whose name typically ends in .tar.
tar is invoked by
where destination is the name of the tape device or tar file, and source... may be files
and/or directories combined to produce the tar file. One of c, t, or x must be
used.
|
'%
tar ± tape archive
-c (create): creates a new tarfile.
-t (table): lists the files on the tarfile.
-x (extract): extracts the files from the tarfile.
-v (verbose): the size and name of each file put onto or extracted from the tarfile is
displayed.
-o (ownership): on the extraction of files, do OÔ extract the original ownership of
the files and directories. Ôhis avoids the message permission denied when reading
tar_files.
-f (destination): uses the next argument as the name of the tarfile.
It is normally in the form filename.tar (but could also be a device name, such as
/dev/8mm).
|
'&
ïrocesses
|
^ ps
^ kill
^ wait
^ sleep
|
|
As soon as the user logs in, a process is created which executes the
login shell.
|
It fetches the pid, tty, time and the command which has started the
process.
^ -f lists the pid of the parent process also.
^ -u lists the processes of a given user
^ -a lists the processes of all the users
^ -e lists all the processes including the system processes
|
|
jobs
^ List the background process
fg %
^ Runs a process in the foreground
bg %
^ Runs a process in the background
nice
|
^ rill -9 (SIGrILL)
^ Terminates the process abruptly
|
^ Sample entries
root:x:0:0:root:/root:/bin/bash
xfs:x:43:43:X Font Server:/etc/X11/fs:/bin/false
suresh:x:500:500:SURESH:/home/suresh:/bin/bash
perumal:x:501:501::/home/perumal:/bin/bash
user:x:502:502::/home/user:/bin/bash
user1:x:503:503::/home/user1:/bin/bash
|
|
|
|
|
|
ï
ù
iser Aode
rernel Aode
|
|
Ôhe history concept provides the user with the capability of calling and editing
previously used commands, modifying others, listing the last commands used,
and so on. ere are some of the commands using the Y shell history concept:
|
Ôhe alias mechanism provides the user with the ability to rename a command, or
change the default options of a command.
Ôhe list of aliases is usually defined in either the .cshrc file in the user's home
directory and/or in /etc/cshrc X
in linux)
|
^ When the user enters a command string, the shell parses the
string into following components:
|
|
|
|
|
|
^ Condition checking
^ Loops
^ Input and output statements
|
|
%
Executing shell script
sh script1.sh
./script1.sh
|
#! /bin/bash
#
# The above line has a special meaning. It must be the
# first line of the script. It says that the commands in
# this shell script should be executed by the bash
# shell (/bin/bash).
# ---------------------------------------------------------------
echo ³Hello ùUSER«.´
echo ³I hope you like working with shell scripts..´
# ---------------------------------------------------------------
|
|
^ Examples:
ù 5
ù >56 Ñ / 1 ù
ù >57 Ñ / 1 ù
ù 58Ñ8
ù
58Ñ 9 Ñ
-8
|
^ ù echo ùx
^ ù echo ùtextline_1
^ ù echo ùtextline_2
^ ù echo ùallusers
^ ù echo ùcountusers
|
^ Examples:
ù 5:
ù 58Ñ8 :
|
^ Filename expansion
^ Variable assignment
^ Forming regular expressions etc.
|
^ Asterisk - u
^ Question Mark - ?
^ Square brackets ± [ and ]
^ Single quote ± µ
^ Double quote ± ³
^ Back quote - `
^ Back slash - \
|
^ Examples:
ù x=u ; echo ùx
ù x=?????? ; echo ùx
ù x=[a-p]????? ; echo ùx
ù x=µùUSER sold the book for ù10¶ ; echo ùx
ù x=³ùUSER sold the book for ù10´ ; echo ùx
ù x=³ùUSER sold the book for \ù10´ ; echo ùx
ù x=`who` ; echo ³Current users = ³ ùx
|
^ Within the shell script, you can refer to the parameters through
variables ù1 through ù9.
^ If you need to use more than 9 parameters, you can use the
shift command within the shell script to refer to additional
parameters.
|
----------------------script2.sh--------------------------
echo ³Total parameters entered: ù#´
echo ³First parameter is : ù1´
echo ³The parameters are: ùu´
------------------------------------------------------------
|
|
^ You can use normal operators with the command. For
example,
^ x=10, y=5
1> 5 8 ù ; ù8
1> 5 8 ù * ù8
1>" 5 8 ù < ù8
1># 5 8 ù => ù8
1>$ 5 8 ù ? ù8
|
l0
|
*@ (equal to)
* (not equal to)
* (less than)
* (less than or equal to)
* (greater than)
* (greater than or equal to)
|
^ Please note that you can only compare two integers using the
command.
|
|
|
|
|
|
|
/
/
|
|
/>
/
/>
/
/
|
|
----------------------script.sh--------------------------
#! /bin/sh
usernames=`who | awk {print ù1}`
echo ³Total users logged in = ù#usernames´
#
for user in ù{usernames}
do
echo ùuser
done
------------------------------------------------------------
|
^ The Bash shell provides a Ñ loop. The syntax of this loop is:
Ñ condition
/
command
F
command
/
|
|
|
|
|
sh -v shell_script_name
^ The ³-v´ (verbose) option prints the shell input lines as they are
read by the system.
|
sh -x shell_script_name
|
Comparison between
^ A solution in C
e.g:
The problem is to count the no of lines in a file ( the file is
called the_file)
|
|
|
|
|