2. Outline
Revision
Simple Filter Commands
Filter Using Regular Expression
Redirection of Standard Input and Output
File and Directory Access Modes
Changing the File Permission
Priti Patel 2/20/2024
2
3. Redirection of Standard Input and Output
Terminal: In context of redirection the terminal is generic
name that represents the screen, display or keyboard.
Command output and error message on terminal (Display).
Provides commands input through terminal (keyboard).
When user logs in , the shell makes available three files
representing three streams.
Standard Input- The file (or Stream) for input
Standard Output- The file(or Stream) for output
Standard Error- for Error message. Connected to display.
Priti Patel 2/20/2024
3
4. Redirection of Standard Input and Output
Standard Input: The input of a command be redirected
from a file.
The less-than character < is used to redirect the input of
a command.
case1: wc –l users
case2: wc -l < users
Difference In the first case, wc knows that it is reading
its input from the file users.
In the second case, it only knows that it is reading its
input from standard input so it does not display file
name.
Priti Patel 2/20/2024
4
5. Redirection of Standard Input and Output
Standard Output: If the notation > file is appended to
any command that normally writes its output to standard
output, the output of that command will be written to file
instead of your terminal.
You can use >> operator to append the output in an
existing file.
For Eg: cut –d “ “ –f 2 1.txt > std_out
Priti Patel 2/20/2024
5
6. Redirection of Standard Input and Output
Standard Error: The three standard files are
represented by a number called a file descriptor.
The kernel maintains a table of file descriptor for every
process running in the system.
Three standard streams are :
0-Standard input
1- Standard output
2- Standard error
The descriptor are implicitly prefixed to the redirection
symbols.
Priti Patel 2/20/2024
6
7. Redirection of Standard Input and Output
< , 0< and > ,1> mean same.
Standard error : Enter incorrect command or try to open
nonexistent file, certain diagnostic message show up the
screen.
For Eg.
Cat test > errorfile is incorrect
Cat test 2> errorfile is correct
tty: Knowing your terminal
UNIX treats terminal as a files.
One who wants to know about filename of the terminal you
are using.
tty (teletype)command
Syntax: $tty
Priti Patel 2/20/2024
7
8. File Access Mode
The permissions of a file are the first line of defense in the
security of a Unix system. The basic building blocks of Unix
permissions are the read, write, and execute permissions,
which are described below −
1. Read
Grants the capability to read ie. view the contents of the file.
2. Write
Grants the capability to modify, or remove the content of the
file.
3. Execute
User with execute permissions can run a file as a program.
Priti Patel 2/20/2024
8
9. Directory Access Mode
Directory access modes are listed and organized in the same
manner as any other file. There are a few differences that need to
be mentioned:
1. Read
Access to a directory means that the user can read the contents.
The user can look at the filenames inside the directory.
2. Write
Access means that the user can add or delete files to the contents
of the directory.
3. Execute
Executing a directory doesn't really make a lot of sense so think
of this as a traverse permission.
A user must have execute access to the bin directory in order to
execute ls or cd command.
Priti Patel 2/20/2024
9
10. Changing The File Permission - chmod
When system administrator creates user account, he has to
assign these parameters to the user:
The user-id : both its name and numeric number
The group-id: both its name and numeric number
Chmod command sets the permission of one or more
files for all the categories of users.
The command can be used in two manners:
Relative Manner –By specifying changes to the current
permission
Absolute Manner- By Specifying the final permission
Priti Patel 2/20/2024
10
11. Relative Permission
Here it only changes the permissions specified in command
line & leaves other permissions unchanged.
Syntax: chmod category operation permission filename
Chmod takes as arguments an expression comprising some
letters & symbols that describe the user category & type of
permission being assigned or removed.
User category (user, group, others)
Operation means remove or assign permissions
Type of permission (read, write, execute)
Priti Patel 2/20/2024
11
13. Relative Permission
Abbreviation Used by chmod
Priti Patel 2/20/2024
13
Category Operation Permission
u – User + Assign Permission r – Read Permission
g – Group - Removes Permission w – Write
Permission
o – Others = Assign absolute Permission x – Execute
Permission
a – All(ugo)