Unix 03
Unix 03
Unix 03
Intermediate Level
Recap Day 2
Text Processing Commands
Process Related Commands
Shell variables
3
Communication Commands
Communication Commands
Command Description write
Writes a message to another user who is logged in Can be used by any user
mesg
wall
Syntax
Used to transfer a file from the source $ put filename terminal to the destination terminal Used to transfer a file from destination $ get filename terminal to source terminal Used to transfer multiple files from the source terminal to the destination $ mput file1 [file2] terminal Used to transfer multiple files from $ mget file1 [file2] destination terminal to source terminal
Description
Used to close the FTP session
Syntax
$ bye $ close
Also used to close the FTP session System will give Good Bye close message then type bye This command displays the list of FTP commands that can be used by the user help User can also type ? symbol for the same Used to execute some commands in local machine ![Command] Shifts the control from ftp prompt to local machine
9
$ help $?
$ ![Command [arg]]
telnet
Used for connecting to UNIX Server. Usage
- telnet [hostname]
telnet 10.122.130.17
Server
Authenticated
10
Security Features
These files are used whenever a user logs into the system.
12
Home Directory
Shell
13
14
15
The password entered would not be displayed, even in masked characters (like *,#,etc), on the screen.
Prompts for:
Current Password New Password Confirm New Password
16
File Security
Classes of users for a file.
Owner
Group
Others
Write (w)
Execute (x)
17
File Security
Two modes of setting file permissions
Absolute Mode (Octal Integer) Symbolic Mode (String)
18
x
1
r
4
w
2
x
1
r
4
w 2
x
1
rwxrwxrwx
Owner
19
Group
Others
Symbols
r read , w - write , x execute u owner , g group , o- others, a all users
Example
u+rx Indicates the user has read and execute permissions.
20
21
chmod [0-7][0-7][0-7] filename (Absolute Mode) chmod [ugoa][+-=][rwx] filename (Symbolic Mode)
22
23
Now perform AND operation between System wide default permissions and Ones complement of umask value
110 110 110 AND 111 101 101 ----------------------------------------110 100 100 ----------------------------------------Equivalent permission set: 6(rw-) 4(r--) 4(r--)
Now perform AND operation between System wide default permissions and Ones complement of umask value
111 111 111 AND 111 101 101 ----------------------------------------111 101 101 ----------------------------------------Equivalent permission set: 7(rwx) 5(r-x) 5(r-x)
Directory Permissions
Directory Permission r w x r w r x w x r w x
26
cd
ls
File accessing
X X X
X X
X X X X X
X X X
Syntax
find [path...] [expression]
29
Search a file from current directory $ find . inum 46345 print downwards, which has inode value 46345
Search all files from current directory downwards, which have 2 links
Search all files from home directory downwards, which have permissions 744
30
$ find . name f1 ok rm {} \;
31
The vi Editor
Editor in UNIX
Need for editor in UNIX Types of editor
Line Editor
ed : UC Berkeley ex : Powerful than ed, Bell Systems
33
Fast
Various operations are very fast
34
Highly Case-sensitive
Letters in lower case have a different implementation in comparison with the same letter in upper case
35
Insert Mode
Keys are interpreted as data
Escape Mode
Keys are interpreted for saving/exiting purposes
36
Command mode :
Enter esc
Insert mode
Escape mode
:q
End
37
vi editor commands
To move around [Command Mode]
h, j, k, l, w, b
38
Searching a pattern
Work in Command Mode
/pattern
Searches forward for first occurrence of a pattern.
?pattern
Searches backward for first occurrence of a pattern.
n
Repeats the last search.
N
Repeats the last search command in opposite direction.
39
Pattern Substitution
Work in Escape Mode
:s/ptn1/ptn2
Replaces first occurrence of ptn1 with ptn2.
: s/ptn1/ptn2/g
Replaces all occurrences in the current line.
: m, n s/ptn1/ptn2/g
Replaces all occurrences in lines m to n.
: ., $ s/ptn1/ptn2/g
Replaces all occurrences from current line to end of file.
40
Customizing vi
Work in Escape Mode
The set command
:set showmode :set nu
41
: rew
Permits editing of first file in buffer
: args
Displays names of all files in the buffer
:f
Displays the name of the current file
42
vi Startup File
.exrc
vi reads .exrc before loading settings are permanent for a vi session
43
The Shell
A program that interprets users requests and gives the response of requests to user Provides environment for user programs A command line interpreter that
Reads user inputs Executes commands
45
The Shell
Shell allows three types of commands:
An internal command An executable file that contains a sequence of shell command lines An executable file that contains object code produced by compilation
46
Shell Features
Interactive and background processing Input/output redirection Pipes Wild card matching Programmable
Shell Variables Programming language constructs Shell Scripts
47
Shell Programming
Collection of Shell commands Also called as shell scripts Variables and flow control statements could be added To run a script we need to first set the execute permission on that file Then set the PATH system variable to include the directory path which contains the file
PATH=$PATH:/home/vaniv : is the delimiter and /home/vaniv is added to the list of path
48
Shell Variables
UNIX allows the use of variables at the $ prompt and within shell scripts. Variables are given names, usually meaningful ones, by the user.
Types of variables:
User defined variables System variables
Types of parameters:
Positional Parameters Special Parameters
49
User-defined Variables
User-defined variable can be assigned a value. Used extensively in shell-scripts. Used for reading data, storing and displaying it.
50
Accepting Data
read.
Accepts input from the user. Syntax : read variable_name. Example : read sname
Variable Name
51
Display Data
echo
Used to display a message or any data as required by the user. echo [Message, Variable] Example: echo Infosys Technologies Ltd. echo $sname
Variable Name
52
export command
export
To make a variable a part of environment and also be accessible to the child process (or shell)
54
System/Environmental Variables.
Besides User-defined variables, the shell also has special variables called environmental variables. Some examples of environmental variables are the HOME, PATH, PS1 and LOGNAME variables
HOME
Contains the home directory for the user.
PATH
Contains a list of all full path-names of directories that are to be searched for executable programs. These names are separated by colon.
PS1
Contains the system prompt.
LOGNAME
Contains the users login name
55
set command
set command
Used to display all the environment variables. Shows the current value of system variables. Also allows conversion of arguments into positional parameters. Syntax : set
56
57
2.
Summary
Communication Commands Security features The find Utility vi editor and its important features Shell Programming
Shell variables read and echo commands set command
59
Thank You
60