unix overview
DESCRIPTION
Unix OverviewTRANSCRIPT
UNIX
“ Let Your Light Shine … “
UNIX is, in short, a good operating system, for UNIX is, in short, a good operating system, for programmers. programmers.
-- Kernighan and Pike-- Kernighan and Pike.
04/22/23
204/22/23Confidential © Tech Mahindra 2006
Session Plan
Introduction to Unix General UNIX commands Utilities in UNIX Advanced Commands Regular Expressions Introduction to Man- Help VI Editor
04/22/23
304/22/23Confidential © Tech Mahindra 2006
References
Rebecca Thomas and Yates : A User Guide to the Unix System,
Mc. Graw Hill, 1985
Kernighan and Pike : The Unix Programming
Environment, PHI, 1990
Stephen G. Kochan & Patrick H. Wood : Unix Shell Programming
04/22/23
404/22/23Confidential © Tech Mahindra 2006
Topics Covered Introduction To Unix
History , Flavors , Features , Components , Architecture &
File System in Unix Unix Commands
External , Internal, I/O Redirection , Filters & Pipes.
Unix Utilities Text Processing,File Handling,Compression, Process Oriented & Communication
VI Editor About Help in Unix
04/22/23
504/22/23Confidential © Tech Mahindra 2006
Introduction to Unix
Unix Stands For
Uniplexed Computing System
It is a popular Multi User ,Multi Tasking &
Time Sharing Operating System.
It has become the operating system of choice
for engineering and scientific workstations.
04/22/23
604/22/23Confidential © Tech Mahindra 2006
History of Unix1965 : AT & T Bell Laboratories, GE Developed MULTICS1969 : Bell Laboratories Developed an Operating System known as UNIX1972 : UNIX re-written in C Language1977 – 82 : Widely Available and Popular for Scientific calculations1983 : System III Release1985 : System V Release1992 : 4.4 BSD (Berkeley’s Software Distribution)1999 : LINUX, A free ware flavor of UNIX by Linus Trivolds is Released
04/22/23
704/22/23Confidential © Tech Mahindra 2006
Flavors of Unix Company Flavors
IBM AIX (Advanced Interactive Executive)
HP HP UxSun Micro Systems SolarisCompaq True 64 Bit UnitSCO SCO Enterprise Server
(Santa Cruz Operation)Micro Soft XENIX HCL MAGNIX
04/22/23
804/22/23Confidential © Tech Mahindra 2006
Features of UNIX
Multi User & Multi Tasking Security Background Processing Pipes and Redirection Tools Hierarchical File System Communication Unix Shells Portability
04/22/23
904/22/23Confidential © Tech Mahindra 2006
Components of UNIX 1 of 7
Applications Utilities Shell Kernel
04/22/23
1004/22/23Confidential © Tech Mahindra 2006
Components of UNIX 2 of 7
Applications :User Written Programs , All applications of Unix runs in Non –
privileged mode of operation known as “User Mode”.
Utilities :It Comprises of Standard Utility Programs (i.e., Shell, Editors
and etc.) and Standard Libraries (i.e., Open, Close, Read, Write, Fork and
etc.,)
04/22/23
1104/22/23Confidential © Tech Mahindra 2006
Components of UNIX 3 of 7
Shell :It acts as an interface between the User and the
Kernel. It is known as the command interpreter. The Function of the
shell is to interpret the commands and conveys them to the kernel
Types of Shells Bourne Shell (bash) Korn Shell (ksh) C Shell (csh)
04/22/23
1204/22/23Confidential © Tech Mahindra 2006
How the Shell is Created ? The init process forks and execs a getty for every
active communication port or line. Each one of these gettys prints the login prompt on the respective terminal and then goes off to sleep. When the user attempts to login, getty wakes up and forks – execs a login program to verify the login name and the password entered. On successful login, login fork-execs the process representing the login shell.
init getty login shell
fork -execs fork -execsfork -execs
Components of UNIX 4 of 7
04/22/23
1304/22/23Confidential © Tech Mahindra 2006
The Login sequence Login id and password. The /etc/passwd file. The /etc/profile and .profile file. Shell prompt.
Components of UNIX 5 of 7
04/22/23
1404/22/23Confidential © Tech Mahindra 2006
/etc/passwd file
- It contains all the login information about each user.- The fields in the password file are separated by
colons and are laid out like this :- login-id:encrypted-password:uid:group-
id:miscellany:login-directory:shell
- To view the contents of this file ,cat /etc/passwd
Components of UNIX 6 of 7
04/22/23
1504/22/23Confidential © Tech Mahindra 2006
Components of UNIX 7 of 7
Kernel :It is the core of the OS – a collection of routines mostly written
in C. These routines communicate with the hardware directly. Kernel
executes in privileged mode of operation, known as “Kernel Mode”
Functions Process Management Memory Management File Management
04/22/23
1604/22/23Confidential © Tech Mahindra 2006
Unix System Architecture
HARDWARE
KERNEL COMPILERS
OTHER
APPLICATIONS
DATABASEPACKAGES
UNIXCOMMANDS
SHELL SHELL
SHELLSHELL
User
UserUser
User
04/22/23
1704/22/23Confidential © Tech Mahindra 2006
Command Interpretation
User Types CommandShell Executes Utility to Carry out Command
Shell Asks For a Command
User Interacts with Utility
Shell Prompts For Next Cmd.User Types Control - d
Logout
LOGIN
04/22/23
1804/22/23Confidential © Tech Mahindra 2006
A hierarchical structure. Consistent treatment of file data. Treatment of peripheral devices as files. Information of files is stored in inode-block. Unix keeps track of files using inode numbers.
The disk space allotted to a Unix File System is made up of blocks. By default the block size is 512 Bytes. It can be multiples of 2.
Unix File System
04/22/23
1904/22/23Confidential © Tech Mahindra 2006
Types of Blocks Boot Block : Contains a Program called Boot Strap
Loader. Super Block : Describes the State of the System Inode Block : Information Related to all these files.
Each entry in Inode block is made up of 64 bytes and contains the following detailsa. Owner b. Group to which the owner belongsc. Type of file d. File Access Permissions
e. Date and Time of (Last Access and Modification)f. Number of Links to the file g. Size of the file
h. Address of blocks where the file is physically stored
Data Block : It Contains the File Contents.
04/22/23
2004/22/23Confidential © Tech Mahindra 2006
/ (root)
bin dev etc tmp lib usr
sh ls tty lp
passwd terminfo user1
user2
home
Structure of Unix File System
04/22/23
2104/22/23Confidential © Tech Mahindra 2006
Directory Organization in Unix
/bin : Executable System Utilities (sh, cp , rm & …) / lib : Operating System and Programming
Libraries. /dev : Device Related Files /etc : System Configuration files and
databases. /tmp : System Scratch Files /usr : Home Directories of all users
04/22/23
2204/22/23Confidential © Tech Mahindra 2006
Absolute Path and Relative Path.The Absolute Path.
The entire pathname starting from root(/).
Eg. : /home/trng10/file1.The Relative Path.
The path relative to your present working directory.Eg.: trng10/file1.
Note :.. : Represents the Parent Directory. : Represents the Present Working Directory
File Systems in Unix
04/22/23
2304/22/23Confidential © Tech Mahindra 2006
“Files have places, and processes have life”. Commands – are essentially files containing programs
mainly written in C. These files are stored in certain directories. The easiest way of knowing the location of any executable program is to use the type command:
$ type lsls is /bin/ls
Type looks up only the directories specified in the PATH variable.
The essential Unix commands for general use are located in the directories /bin and /usr/bin
Files, Processes & Commands
04/22/23
2404/22/23Confidential © Tech Mahindra 2006
Unix Commands
Commands : It is a program that tells UNIX System to do
something. It has the form.command <options> <arguments>
Note :1. Option is generally preceded by – (hyphen)
symbol2. More than one option can be used together.
04/22/23
2504/22/23Confidential © Tech Mahindra 2006
Types of Commands
1. External Commands : These are stored as files having an independent existence. The shell creates a process for each of these commands that it executes while remaining their parent.
E.g.. cat, ls
2. Shell Scripts : The shell executes these scripts by spawning another shell, which then executes the commands in the script. The child shell becomes the parent of the commands that feature in the script.
3. Internal Commands : These are shell built-ins, not stored as separate files. The shell does not generate a process for these commands and executes them directly.
E.g.. cd, echo
04/22/23
2604/22/23Confidential © Tech Mahindra 2006
File & Directory Related Commands
1. ls : List the contents of the Current Directory2. ls bms : List the contents of the directory bms3. ls –l : Used for Long Listing of Commands4. ls –al : Used to have a long listing including the hidden files.5. ls –i : Used to Display the Inode number of the files 6. ls –s : Used to display the files along with their sizes7. ls –r : Used to display the files in the reverse order8. ls –R : Used to display the files in a recursive manner
(i.e., including the sub folders from the current directory).9. ls –ul : Used to display the last access time of the files and
directories in the current working directory with long listing
04/22/23
2704/22/23Confidential © Tech Mahindra 2006
Meta Characters* : Matches More than one Character? : Matches one character[…] : Matches one character from the group specified.Eg. : a. ls [aeiou]* (used to display the file namesstarting with any of the vowels). b. ls [a-z][0-9] (used to display the file names whose first character is an alphabet from a to z and the second character is an digit from 0 to 9).! : Complements the Given Condition.Eg.: ls [!ab]* (Displays all the files except that are starting with a or b).
File & Directory Related Commands
04/22/23
2804/22/23Confidential © Tech Mahindra 2006
File & Directory Related Commands
1. Create a File : There are 2 commands available to create the file a. touch : Creates an Empty File
Syntax : touch <file name> …
Eg.: a. touch jncb. touch jnc christ aba
The first command is used to create an empty file jnc and the later one is used to create four empty files named jnc, christ and aba on the current directory.
04/22/23
2904/22/23Confidential © Tech Mahindra 2006
File & Directory Related Commandsb. cat : Creates the file with contents
Operators : > , >>> : used to create a new file>> : used to Append some contents to the end
of the existing file. (if the file exists)
Syntax : cat <operator> <file name>
Eg. : a. cat > magb. cat >> bms
Note : After this command press control d to save the contents to
the file.
04/22/23
3004/22/23Confidential © Tech Mahindra 2006
File & Directory Related Commands
2 . To Read the File :The cat command is used to read the contents of the file. (cat is used for both creation and reading operation). While reading we use < (Input operator) it is optional.
Syntax : a. cat <filename> b. cat <operator> <file name>
Eg. : a. cat Techm b. cat < Techm
Note : Both the commands will give us the same result.
04/22/23
3104/22/23Confidential © Tech Mahindra 2006
File & Directory Related Commands
3. To Copy the FileThere are 2 commands available to copy the contents of one file
to another.Commands : cp & ln
The first command is used to copy the content of one file to another in a different memory location but the later is to
provide a link (i.e.., within the same address location).
Syntax : cp <source file> <Destination file>Eg. : cp bms balaji
04/22/23
3204/22/23Confidential © Tech Mahindra 2006
File & Directory Related Commands
a. cp –i <file1> <file2> : Asks confirmation provided if the file2 exists b. cp –rd <dir1> <dir2> : Copies the content of the dir1 to dir2 (if dir2 exists or not, if not it creates the dir2 and then copies it)
Eg : cp -rd a1 bmsIf the directory bms exists it copies the contents of a1 inside the directory bms. Otherwise it creates a directory bms and then copies the information.
04/22/23
3304/22/23Confidential © Tech Mahindra 2006
File & Directory Related Commands
In the case of later one, there are 2 types of links can be provided,
a. Hard Link b. Symbolic/Soft LinkHard Link Soft Link
Same inode address for both the files
Different inode address for the original and linked one.
Cannot create a link without the file
Can be created without a original file
Link will get existed after deleting the original file
Link will not exist after deleting the original file
Cannot be established for directories
Can be established for directories
04/22/23
3404/22/23Confidential © Tech Mahindra 2006
File & Directory Related Commands
a. Syntax to create a Hard Linkln <file name> <link name1> Eg.: ln bms balaji
b. Syntax to Create a Symbolic/ Soft Linkln –s <file/directory name> <link name>Eg.: ln –s bms srinu
Note : By DefaultFiles : 1 linkDirectory : 2 links
We can copy a link.
04/22/23
3504/22/23Confidential © Tech Mahindra 2006
File & Directory Related Commands
4. To Rename / Move the FileSyntax: mv <source file> <destination file>
If both the source and destination file belong to the same directory then it is renaming the file.
If the source file is in one directory and the destination is in another directory the command moves the source file from the current directory to the path mentioned in the destination fileEg. : a. mv bms balab. mv bms ./magi (or) mv bms /home/magesh/magi
The first one is used to rename the file bms to bala within the current
directory. But the later one is used to move the file bms from the current
directory to the directory named magi.
04/22/23
3604/22/23Confidential © Tech Mahindra 2006
File & Directory Related Commands
5. To Remove the Filea. rm <filename> : Removes the file b. rm –i <filename> : Removes the file interactivelyc. rm –r <directory name> : Removes the directory recursivelyd. rm -f <file name> : Removes the file forcibly which is not having the write permission.
6. To Display the Type of fileSyntax : file <* /filename>Eg : a. file * b. file bms
04/22/23
3704/22/23Confidential © Tech Mahindra 2006
File & Directory Related Commands7. To Create a Directory
a. mkdir <directory name> : To create the directory from the current working directory b. mkdir <path>/<directory name> : To create the directory in the specified path. c. mkdir <directoryname1 . . . > : Creates multiple directories in the current working directory. d. mkdir –p <directory name1/ ./ . >: Creates sub- directories within one another .
Eg : mkdir –p a/b/ cCreates directory a in the current directory within
a creates a directory b and within b creates an another directory c.
04/22/23
3804/22/23Confidential © Tech Mahindra 2006
File & Directory Related Commands8. To Change the Directory
a. cd : Moves to the home directoryb. cd / : Moves to the root directory (i.e. />)c. cd .. : Moves to the Parent directoryd. cd <directory name> : Moves to the directory name specified
9. To Remove the Directory a. rmdir <directory name> : Removes the directory (provided it should be empty) b. rm –r <directory name> : Removes the directory along with its contents.
04/22/23
3904/22/23Confidential © Tech Mahindra 2006
File & Directory Related Commands10. To Rename the Directory
Syntax: mv <directory name> <new name>Eg : mv bms bmsma
The above command is used to rename the directory in the current working
directory. (i.e., the directory bms has been renamed as bmsma in the current working
directory)11. To Move the Directory
Syntax: mv <directory name> <path>Eg : mv bms /home/magesh
The above command is used to move the directory bms from the current working directory to /home/magesh.
12 . To Display the Present Working DirectorySyntax : pwd
04/22/23
4004/22/23Confidential © Tech Mahindra 2006
Processes in UNIX
A process is a program in execution. Each process is allocated a process- identifier or PID. In general , each process is started by another, known as
parent process. When system starts, it runs a single program, the process
number one called init ( PID = 1). Scheduler (schd) is the first process to be invoked with
PID=0
04/22/23
4104/22/23Confidential © Tech Mahindra 2006
Processes in UNIXWhen you enter a command, what
processing does it go through before it is executed?
The shell first scans the entire command and its arguments for
meta characters. If it sees symbols like the *, it selects those filenames
that match the pattern. If it sees the >, it redirects the information to a
file following the >. Finally it directs the kernel to execute the
command.
04/22/23
4204/22/23Confidential © Tech Mahindra 2006
The process that are automatically invoked and terminated are called daemons (System processes).
lpsched is a printer daemon sendmail is for send/rx mails---daemon
Daemon process
04/22/23
4304/22/23Confidential © Tech Mahindra 2006
Process related commandsa. ps : Displays the currently running processes of that user.
b. ps –a : Displays the process list of all users
c. ps – t terminal name : Processes invoked by that terminal
d. ps –u username : processes invoked by that user
e. ps –f : Displays additional info such as parent process id, start time etc.
f. ps –e : Displays all the processes including the daemon processes
04/22/23
4404/22/23Confidential © Tech Mahindra 2006
a. kill process idb. kill -9 pid will forcibly (sure) kill c. kill -9 $$ will kill present shell or logout
Across the terminal column there is a ? indicating that there is
no terminal for this. Such processes cannot be killed
Process Termination
04/22/23
4504/22/23Confidential © Tech Mahindra 2006
Other commandsa. who : Displays the info regarding all the currently
logged in users
b. who am I : Displays the info regarding the user who invokes this command
c. uname : Represents the flavor of Unix in which we operate on.
d. date : Display the current date with time
04/22/23
4604/22/23Confidential © Tech Mahindra 2006
AliasesBash & Korn support the use of aliases that let you assign shorthand names for frequently used commands.Eg.: $ alias “bms=ls –l”
Once the alias is defined, we can execute ls –l command simply by using bms.
You can display an alias definition by using alias with the name :Eg. : $ alias bmsbms=‘ls –l’
You can drop an alias by using unalias with the name:Eg.: $ unalias bms
04/22/23
4704/22/23Confidential © Tech Mahindra 2006
I/O Redirection >file : Make file as the standard outputEg : cat > bmsWrites the content into the file specified
< file : Make file as the standard inputEg : cat < bms
>> file : Make file as the standard output and append to it if it existsEg : cat >> bms
<<word :Take shell input up to the line containing word or up to the end of the fileEg : cat << bmsThe above starts taking the input from the user till the user types the word
bms. Once when the user types bms it terminates the input (closes the standard input
file).
04/22/23
4804/22/23Confidential © Tech Mahindra 2006
Try Out cat file1 file2 > file3 :
Contents of file1 and file2 are concatenated and written to file3
cat < file1 : Displays the Content of file1
cat < file1 > file2 : Transfers the content of file1 to file2
cat >file1<file2: Transfers the content of file2 to file1
04/22/23
4904/22/23Confidential © Tech Mahindra 2006
date;who :Displays the date and the information
about all the users logged on to the system. date;who>users :
Writes only the content of who command to the file named users and the output of date command will be displayed on the monitor.
(date;who)>users : Writes the output of both the
commands to the file named users cat <<end >file1 :
It closes the file file1 once when we type the word end and press the enter the key (the line should have only one word).
Try Out
04/22/23
5004/22/23Confidential © Tech Mahindra 2006
FiltersFilter is a program which can receive a flow of data from standard
input, processes it and sends the results to the standard output.
Filters in UnixFilters Purposecat Concatenates and displays
files.pg Paginates display for
terminalsmore Displays the information
one screen at a time.grep Searches file for a patternsort Sorts and merges files
04/22/23
5104/22/23Confidential © Tech Mahindra 2006
Filters (Contd.)
head Prints the first few lines of the file
tail Prints the last few lines of the file
cut Cuts out selected fields of each line of a file
paste Merges lines of a fileuniq Reports repeated
lines in a filenl Adds line numbers to
the file cat a | nl
tr Translates character by character
04/22/23
5204/22/23Confidential © Tech Mahindra 2006
PIPES
A data-connection between two or more commands where in the output of one command acts as an input to next command.
Usage : Command1 | Command2. Command1 | Command2 | Command3.
Saves time and disk-space
Note :In a pipeline, the command on the left of the | transfers the output to the command on the right and so on.
04/22/23
5304/22/23Confidential © Tech Mahindra 2006
Pipes (Contd.)
Process1 Process2
process
input output
Output 1 Input 2pipe
A single process :
The use of Pipe :
04/22/23
5404/22/23Confidential © Tech Mahindra 2006
Pipes (Contd)
ls –al | more : Displays the contents of the current directory
page by page.
ls –al | less (or) ls –al |pg : Displays one screen of information &
according to the users representation it displays the number of lines.
cat names | wc -l :The above command tells us the total number
of lines available on the file named names.
04/22/23
5504/22/23Confidential © Tech Mahindra 2006
Important Note
Commands that take neither standard input nor standard output
mkdir, cd, rmdir, cp, mv, rm
Commands that don’t take standard input but send their output to standard output
ls, pwd, who
Commands that use both standard input & standard output
cat, wc, bc, cmp
04/22/23
5604/22/23Confidential © Tech Mahindra 2006
Tee Command Reads the input and writes to standard output device
and file
tee is an external command and not a feature of the shell. It handles a character stream by splitting its input into two components. It saves one component in a file and writes the other to the standard output. Being also a filter, tee can be placed anywhere in a pipeline. Tee doesn’t perform any filtering action on its input; it gives out exactly what it takes.E.g who | tee user.txt
tee command displays the output of who and saves this output in a file, user.txt as well
04/22/23
5704/22/23Confidential © Tech Mahindra 2006
Another e.g. of tee command
who | tee /dev/tty | wc –lTee “saved” the who output in /dev/tty, (the terminal is also a file) thus effectively showing it on screen. wc –l counted the other stream.
ls –al | tee filelist Stores the output of the command ls –al command in the file named filelist
ls –al | teeIt will display the output of the above command on the monitor and the file output will be suppressed
04/22/23
5804/22/23Confidential © Tech Mahindra 2006
File SecurityPermissions for a file
read (r) 4 write (w) 2 execute (x) 1
Classes of usersOwner denoted by (u)Group denoted by (g)Others denoted by (o)
Nine bit field Composite permission for each file.
04/22/23
5904/22/23Confidential © Tech Mahindra 2006
Default File Permissions Calculate system default file permissions 6 6 6 - System wide default permissions 0 2 2 - Denial ‘mask’ set by UMASK ---------- 6 4 4 - Resultant permissions that will be
set on all files created (-rw-r--r--)
04/22/23
6004/22/23Confidential © Tech Mahindra 2006
Default Directory Permissions
System wide default permissions for a directory: rwxrwxrwx (777)
UMASK Default permissions for a directory:
7 7 7 - System wide default permissions 0 2 2 - Denial ‘mask’ set by UMASK ----------- 7 5 5 - Resultant permissions that will be set on
alldirectories created (drwxr-xr-x)
04/22/23
6104/22/23Confidential © Tech Mahindra 2006
Changing umask value
umask User Maskable ValueSyntax : umask <integer value>
Eg. :umask 242
All the new files will have 424 (666-242). All the new directories will have 535 (777-242)
04/22/23
6204/22/23Confidential © Tech Mahindra 2006
File Permissions
Permission
Possible Operations Not Possible Operations
r Reading, Rename , Copying & Move
Remove , Append & Modification
w Rename , Move, Remove
Reading, Append & Modification
x Move , Rename Read, Append, Modification, Copy & Remove (Asks for Confirmation)
Note : It represents only to the owner of the file
04/22/23
6304/22/23Confidential © Tech Mahindra 2006
Directory Permissions
Permission
Possible Operations Not Possible Operations
r Rename & Removing Open (i.e., cd not works) , Copy & Move
w Rename , Move, Remove
Open & Copy
x Open & Rename Listing , Copying & Move
Note : It represents only to the owner of the directory
04/22/23
6404/22/23Confidential © Tech Mahindra 2006
Setting File & Directory Permissions
The user can change the default security permissions for his/her
own files. The command used to change the security for the files chmod. There are 2 different methods available to implement the
file security they are
Absolute Mode (Octal integer) Symbolic Mode (String)
Note :Octal :
One shot
Symbolic : For a u/g/o - rwx is in one shot For a r/w/x - ugo is done in multiple commands
04/22/23
6504/22/23Confidential © Tech Mahindra 2006
a. Absolute Mode (Octal Integer )i. Represented by numbers (Read = 4, Write = 2, Execute = 1).
ii. It can have a value ranging from 000 to 777.Syntax For Numeric Mode
chmod <numbers> <files>Eg.: chmod 777 bms
The above example changes the default file permissions of the file bms to 777 (i.e., Owner, Group & others have all the
permissions read, write & Execute).
Setting File & Directory Permissions
04/22/23
6604/22/23Confidential © Tech Mahindra 2006
b. Symbolic Mode Representing specifically for the owner, group and others
Syntaxchmod <who> <+/- => <permission> <file>
Note: who : u , g or o (Owner , Group & Others) + adds , - removes and , = assigns the permission
. permission : r or w or x
The Various ways to change the security of the file using symbolic mode is
Setting File & Directory Permissions
04/22/23
6704/22/23Confidential © Tech Mahindra 2006
1. chmod u=rwx,g=rw,o=r file1The above example is used to set all the permissions to owner, only
read and write to group and read to others for the file named file12. chmod g+x, o+rw file1
The above example is used to set the permissions only for the group and others . It will append execute to Group and read and
write to others for the file named file1. It won’t change the default
permission for the owner.3. chmod o-w file1
The – sign is used to remove that permission from the file. In this case we remove the write permission for the file named file1
from others. Note : No spaces before or after the + or – sign.
Setting File & Directory Permissions
04/22/23
6804/22/23Confidential © Tech Mahindra 2006
Try out
1. chmod 470 bmsChanges the security permission for the file bms ,
owner will have only the read permission, group will have all the
permissions and others will have no permissions.2. chmod ugo=rwx bms
Changes the security permission for the file bms , All the
permissions has been given to owner, group and others3. chmod rw = ug bms
Error
04/22/23
6904/22/23Confidential © Tech Mahindra 2006
Changing Owner and Group Change the owner of a file (or directory)
Syntax : chown <newowner> <file/directory>
Eg.: chown jnc textfile
Change group to which a file belongs:Syntax : chgrp <new group>
<file/directory>Eg.:
chgrp jnccs textfile
04/22/23
7004/22/23Confidential © Tech Mahindra 2006
Important Notechmod :
It can be executed only by the user (owner) & thesuperuser.
chown :On BSD based systems, only, the system administrator can
change a file’s owner with chown.command
chgrp : Owner can change the group only when he belongs to
the other group
04/22/23
7104/22/23Confidential © Tech Mahindra 2006
About Help in UNIX what is : Tells you precisely about the
functionality of that command
help : Displays all the shell script commands
type : Tells you about where that command has
been placed.
man : Gives the detail description about the
command
04/22/23
7204/22/23Confidential © Tech Mahindra 2006
Text Processing Utilities. tr :
Used to translates character/characters.Syntax : tr <string1> <string2> Eg.:
a. tr “[a-z]” “[A-Z]”The above command is used to replace all
the lower case alphabets to upper case letters.b. tr “b” “abc”
The above command replaces the character b with the
first character on string 2 (i.e., a) c. tr “magesh” “bms”
The above command is used to replace m with b , a with m,g with s and all the remaining characters with the last character on the second string.
04/22/23
7304/22/23Confidential © Tech Mahindra 2006
Text Processing Utilities.
Eg.: d. tr “[a-z]” “[A-Z]” < bms
It converts the contents of the file named bms from
lowercase characters to uppercase characters and displays the output on
the standard output device.
e. tr –c a AThe above command is used to convert all
the other
characters except a to A (including the enter key and white space).
04/22/23
7404/22/23Confidential © Tech Mahindra 2006
Text Processing Utilities. (Contd.)
cut :Used to cut the characters or fields (i.e.,
words ) from the given file.
Syntax : cut <options> <file1 … > Options
c : To Cut the Charactersf : To Cut the Fieldsd : Represents the delimiter
Note : Default delimiter for the cut utility is tab.
04/22/23
7504/22/23Confidential © Tech Mahindra 2006
Text Processing Utilities. (Contd.)
Eg.: a. cut –c2 bms : It is used to display the second character in each and every line of the file named bms. b. cut –c2,4 bms : It is used to display the second and the fourth character in every line of the file named bms. c. cut –c2-4 bms : It is used to display from the second to the fourth character in every line of the file named bms. d. cut –f2 –d” “ bms : It is used to display the second word in every line of the file named bms. By default it takes the space as the delimiter e. cut –f2,4 -d” “ bms : It is used to display the second and fourth word in every line of the file named bms, including the delimiter. f. cut –f2-4 –d” “ bms : It is used to display the second to the fourth word in every line of the file named bms , including the delimiter.
04/22/23
7604/22/23Confidential © Tech Mahindra 2006
g. cut –f2-4 –d”:” bms : It is used to display the second to the fourth field including the delimiter in every line of the file named bms, with “:” as the delimiter.
Note :The user can change the delimiter, the changes are
said to be temporary.While using more than one option it has to be
separated by spaces.
Text Processing Utilities. (Contd.)
04/22/23
7704/22/23Confidential © Tech Mahindra 2006
Text Processing Utilities. (Contd.)
paste : Used to combine the contents of the files line by line
and displays it on the standard output device (i.e., Monitor)Syntax : paste <file1 file2 . . . >
Eg.:a. paste pas1 pas2b. paste pas1 pas2 pas3
04/22/23
7804/22/23Confidential © Tech Mahindra 2006
Text Processing Utilities. (Contd.)
cmp : Compares the Content of the given two files
Syntax : cmp <file1> <file2>
Eg.: cmp a4 a5
Note : This command is used to compare the contents of the
given 2 files line by line once when it finds a non matching character immediately it stops its execution and prompts the user in which particular line and the character the files gets differed.
04/22/23
7904/22/23Confidential © Tech Mahindra 2006
Text Processing Utilities. (Contd.)comm :
Used to compare the contents of the given 2 files line by line till the end of the file. The output of the above command will be displayed in matrix format with 3 columns and the number of rows depends upon the number of lines in the file.
Syntax: comm <file1> <file2>Eg.:comm comm1 comm2
Note : 1st Column : Unique lines in File1 2nd Column : Unique lines in File2 3rd Column : Common lines between the given 2 files.
04/22/23
8004/22/23Confidential © Tech Mahindra 2006
Text Processing Utilities. (Contd.)
diff :Used to display the differences between the given
two filesSyntax : diff <file1> <file2>Eg.:diff diff1 diff2
uniq : Used to remove the duplicate words in the file
which appears continuously. (It is case sensitive)Syntax : uniq file1Eg.:uniq uniq1
04/22/23
8104/22/23Confidential © Tech Mahindra 2006
Text Processing Utilities. (Contd.)
What is the difference between comm, cmp, and diff text processing utilities?
comm cmp diffThis utility is used to compare the entire file line by line and displays the output in 3 different columns (uncommon lines in both the files will be displayed in the first 2 columns and the last column represents the common lines in both the files).
This utility compares line by line and stops its execution, once when it finds a non- matching character. It prompts the user in which particular line and the character position the file gets differs.
It totally tells us the number of lines gets differs between the given two files.
04/22/23
8204/22/23Confidential © Tech Mahindra 2006
Text Processing Utilities. (Contd.)
sort : Used to sort the contents of the given file or the
input from the standard input device.Syntax : sort <options> <file>Options
o Creates an Output Fileu Displays Unique linesm Merges the given filesr Reverse Sortn Numeric Sorting (i.e., in Ascending
order)
04/22/23
8304/22/23Confidential © Tech Mahindra 2006
Eg.: a. sort sort1 : Sorts the content of the file sort1 in ascending order.
b. sort : Takes the input from the standard input device and then sorts it and displays it on the standard output device.
c. sort –n sort1 : Used to sort the numbers in ascending order, By default it does the
sorting in alphabetical order.
d. sort –r sort1 : Used to sort the contents of the file named sort1 in reverse order.
e. sort –u sort3 : Used to display the sorted output of the contents of the file named sort3 by removing the duplicate lines.
Text Processing Utilities. (Contd.)
04/22/23
8404/22/23Confidential © Tech Mahindra 2006
Eg.:f. sort –m sort1 sort3 :
Sorts the contents of the files sort1 and sort3 ,then merges its content and displays it on the standard output device. (For this option first both files has to be sorted then it has be merged, otherwise it displays the results in unsorted manner).
g. sort –o sort1 sort4 : Sorts the contents of the file sort4 and stores
the output on to the file sort1. (It is similar to sort sort4 > sort1)
Text Processing Utilities. (Contd.)
04/22/23
8504/22/23Confidential © Tech Mahindra 2006
Text Processing Utilities. (Contd.)
head :Used to display the specified number of lines
from the beginning of the file.
Syntax : head <number> <file>Eg.:a. head -5 bms : Used to display the first 5
lines from the beginning of the file named bms.b. head +5 bms : Used to display the first 10
lines from the beginning of the file named bms.c. head bms : Used to display the first 10 lines
from the beginning of the file named bms.Note : By default it prints the first 10 lines from the beginning of the file.
04/22/23
8604/22/23Confidential © Tech Mahindra 2006
Text Processing Utilities. (Contd.)
tail :Used to display the specified number of lines
from the end of the file.
Syntax : tail <number> <file>Eg.:a. tail -5 bms : Used to display the last 5 lines
from the end of the file named bms.b. tail +5 bms : Used to display from the 5th
line till the end of the file named bms.c. tail bms : Used to display the last10 lines from
the end of the file named bms.Note : By default it prints the last 10 lines from the end of the file.
04/22/23
8704/22/23Confidential © Tech Mahindra 2006
Text Processing Utilities. (Contd.)
wc :Counts the total number of lines, words and characters in the given file.
Syntax : wc <options> <file>Options:
-l : Displays the total number of Lines in the file.
-w : Displays the total number of words in the file.
-c : Displays the total number of characters in the file
Eg.: a. wc bms : Displays the total number of lines, words and characters in the file named bms.
b. wc –l bms: Displays only the number of lines in the file name bms.
04/22/23
8804/22/23Confidential © Tech Mahindra 2006
Text Processing Utilities. (Contd.)
grep : grep stands for Globally Search a Regular
Expression and Print it. The term regular expression refers to the generalized search pattern that grep accepts. grep searches out these patterns globally (for an entire file, not just a single line) and prints out the lines containing them.
The most basic form of grep isgrep <options> <pattern>
<filename>
In the case of grep command we can search for only one pattern, The extended version of grep command is said to be egrep which stands for Extended Globally Search a Regular Expression and Print it. Which is used to search more than one pattern at a time from the given file.
04/22/23
8904/22/23Confidential © Tech Mahindra 2006
Text Processing Utilities. (Contd.)
Options
Options Meaning-v Prints those lines that do not match-c Prints only the count of the number of
matching lines.-l Prints only the name of the file, if and only
if it matches with the given searching pattern.
-n Prints the line numbers with each output line
-i Ignores cases while searching-s Suppresses error messages
04/22/23
9004/22/23Confidential © Tech Mahindra 2006
Pattern matching metacharacters for grep\ : A backslash escapes a special character
Eg. : grep \* grep1
[dyr] : Matches an d, y or r Eg. : grep “[dyr]” grep1
[a-d] : Matches any one character in the range from a through dEg.: grep “[a-d]” grep2
[^aeo] : Matches any one character except an a, e or oEg.: grep “[^aeo]” grep2
Regular Expressions.
04/22/23
9104/22/23Confidential © Tech Mahindra 2006
^ : Matches the pattern at the beginning of a lineEg. : a. grep ^your grep1 b. grep “^your” grep1
$ : Matches the given pattern at the end of a lineEg. : a. grep your$ grep1 b. grep “your$” grep1
. : Matches for a single character.Eg. : a. grep ^.$ grep4 b. grep “^.$” grep4
Regular Expressions. (Contd.)
04/22/23
9204/22/23Confidential © Tech Mahindra 2006
To Search more than one pattern in a single command we use
egrep
Syntax : egrep “<pattern1>|<pattern2>|…” <filename>
Eg.: egrep “doubt|happiness” grep1
Note :To Know more about egrep in detail see the
manual page of egrep by issuing a command man egrep
Regular Expressions. (Contd.)
04/22/23
9304/22/23Confidential © Tech Mahindra 2006
Text Processing Utilities. (Contd.)
Eg.:a. grep doubt grep1 :
Searches for the pattern doubt in the file named grep1
and print all the lines of the file that matches the pattern.
b. grep –v doubt grep1 :Prints all the lines from the file named
grep1 that never matches the pattern “doubt”.c. grep –c doubt grep1 :
Prints the total number of lines that matches the pattern “doubt” in the given file named grep1.
d. grep –i Doubt grep1 :Prints all the lines that matches the
pattern “Doubt” in the given file named grep1 irrespective of the cases.
04/22/23
9404/22/23Confidential © Tech Mahindra 2006
Hands On head file1
Displays the first 10 lines of the file named file1. head +4 file1
Displays only the first 10 lines from the file named file1. head +0 file1 (or) head 0 file1
Displays the first 10 lines from the file named file1 with an error message and an header information.
tail +2 file1 Displays from the 2nd line till end of the file named file1.
uniq file1Displays the unique lines from the given file named file1.
04/22/23
9504/22/23Confidential © Tech Mahindra 2006
Hands on (Contd.)
who | grep trng01|tee listThe output of who command has been piped to the grep command, the grep command searches for the user named trng01 and prints only those line that matches the searching pattern and the output has been redirected to standard output device and also to the file named list.
grep #include sample.cSearches for the pattern #include in the file named sample.c and displays all those lines that matches the pattern.
grep [a-c]$ file1Displays all those lines that ends with the character either a 0r b or c in the file named file1
04/22/23
9604/22/23Confidential © Tech Mahindra 2006
Write grep commands to match … lines containing only a single digit
Ans : grep “^[0-9]$” grep4
lines containing exactly 3 chars
Ans : grep “^...$” grep4
Hands on (Contd.)
04/22/23
9704/22/23Confidential © Tech Mahindra 2006
File Handling Utilities1. du :
Used to display the block size used by specified files and directories.
Syntax : a. du b. du <files/directory>
Eg.: a. dub. du bms
Note :The first one is used to display the block size of all the
directories and the sub-directories available on the present working
directory. But later one displays the block size of the file or the directory
bms.
04/22/23
9804/22/23Confidential © Tech Mahindra 2006
File Handling Utilities (Contd.)
2. df : Disk Free
Used to display the used as well as the free disk space for all the file
systems installed on the system.
Syntax: a. df <options> b. df <options> <files/directory>
Eg.: a. dfb. df bms
Note :The first one is used to display the block information for all the file systems. But the later one is used to display the information about in which particular file system the file or directory named bms is available.
04/22/23
9904/22/23Confidential © Tech Mahindra 2006
File Handling Utilities (Contd.)
Eg.: df –iThe above command is used to display the inode block
information about the file system.
3. dfspace :It is used to display the disk space in terms of Bytes/Kilo Bytes/ Mega Bytes. This command has to be represented by /etc/dfspace.
Syntax : /etc/dfspace
Eg.: /etc/dfspace
Note : It will not work in Linux
04/22/23
10004/22/23Confidential © Tech Mahindra 2006
File Handling Utilities (Contd.)
What is the difference b/w du, df , dfspace File handling utitlities ?
du df dfspaceIt will display the block size used by all the directories and sub-directories available under the present working directory. (or) It will display the block used by the specified file or directory.
It will display the information about the blocks of different file systems installed on our system. (or) It will give the information about in which particular file system the specified file or directory is available.
It represents the space of the files / directories in terms of bytes / kilo bytes / mega bytes. It has to be preceded by /etc/dfspace
04/22/23
10104/22/23Confidential © Tech Mahindra 2006
File Handling Utilities (Contd.)
4. ulimit : User Limit
Used to signify the largest file that can be created by the user.
Syntax : a. ulimit b. ulimit <number>
Eg.: a. ulimitb. ulimit 2
Note :1. The first one is used to display the current value of the ulimit variable. The second one is used to restrict the size of the block
to be <= 1024 bytes.2. The changes made to the ulimit variable is temporary. i.e., which will be available till the session gets expired.
04/22/23
10204/22/23Confidential © Tech Mahindra 2006
File Handling Utilities (Contd.)
5. find :
Used to search for the files or directories available on the file system.
Syntax : find <options> <files/directory>
Eg.: a. find bmsb. find /home /bms
Note :The first one is used to search for the file/directory named bms on the current working directory. But the later one is used to search for the file/directory named bms available from the home directory.
04/22/23
10304/22/23Confidential © Tech Mahindra 2006
Compression Utilities
Utilities used to reduce the size of the file. Useful when the files are sent over the net. Uses an algorithm to compress files. Similar to WinZip in windows.
04/22/23
10404/22/23Confidential © Tech Mahindra 2006
1. gzip :Used to compress the given files/directories by removing the original files/directories.
Syntax : gzip <options> <file/directory>Eg.:a. gzip a : It compresses the file named a, removes the file named a and creates a new version of a known as a.gz
b. gzip a b c: It compresses the files named as a , b & c by removing the original files and creates a files with the extension a.gz , b.gz and c.gz.
c. gzip –r bms : It is used to compress the contents of the directory bms. (i.e., Recursive compression)
Compression Utilities (Contd.)
04/22/23
10504/22/23Confidential © Tech Mahindra 2006
Note :While using gzip command the user is not allowed to give the
extension for the file which is to be zipped. By default the command
interpreter will give the extension as <filename>.gz.
To Read the contents of the zipped file.To Read the contents of the zipped file . We have two utilities
available they area. zcatb. zmore
The first one is used to read the contents of the compressed file at
a stretch. But the later one is used to read the contents one page then line
by line execution of the command.
Compression Utilities (Contd.)
04/22/23
10604/22/23Confidential © Tech Mahindra 2006
Syntax : a. zcat <options> <compressed file name> b. zmore <options> <compressed file name>Eg.: a. zcat b1.gzThe above command is used to read the contents of the compressed file named b1.gz. b. zmore b1.gz The above command is used to read the contents of the compressed file named b1.gz one page initially and then it displays the information line by line.Note :We have gzcat and gzmore commands which does the same operation as zcat and zmore but the difference is it works only on some flavors of Unix OS.
Compression Utilities (Contd.)
04/22/23
10704/22/23Confidential © Tech Mahindra 2006
1. UncompressionUsed to decompress the given files/directories by removing the zipped files/directories and moving back to the original ones.
Syntax : gunzip <options> <files/directory>Eg.:a. gunzip b1.gzThe above example is used to decompress the file named b1.gz and create the original file named b1 in the current directory. b. gunzip –rd bmsThe above example is used to decompress the contents of the directory recursively and replace it with the original names.
Compression Utilities (Contd.)
04/22/23
10804/22/23Confidential © Tech Mahindra 2006
1. tar :Used to take a back up for the most important files or directories. It
is otherwise called as Archiving of files.Syntax : tar <options> <files/directory>Optionsc Used to copy the files/directories.v Lists the files/directories that are copied.f Indicates the name of the archive file.t Lists the name of the files/directories related to the archive file. (Similar to table of contents)x Extract files/directories for the archived file.Note :Options “c “ & “f” are compulsory while using the tar command.
Compression Utilities (Contd.)
04/22/23
10904/22/23Confidential © Tech Mahindra 2006
Eg.:a. tar –cf tarfiles.tar tarb tarc tarc1The above command is used to create a back up for the files named tarb, tarc, tarc1 and stores the backup in the file named specified tarfiles.tar.b. tar –cvf tarfiels.tar tarb tarc tarc1This command is similar to that of previous one. But the difference is before displaying the prompt it will display the list of files that has been used to create a back up (i.e., tarb tarc tarc1 in a separate lines).c. tar –tf tarfiles.tarThe above command is used to display the list of files/directories that has been included inside the archive file named tarfiles.tar.
Compression Utilities (Contd.)
04/22/23
11004/22/23Confidential © Tech Mahindra 2006
Process Oriented UtilitiesIn case of Unix OS we can execute the process both in foreground as well as in the background.
Background ProcessUnix provides two different types of commands to submit their process in background they are & and nohup (i.e., no hang ups). Limitations
1. On termination of background process no success or failure is reported on the screen.2. Output of a background process should always be redirected to a file.3. Too many processes running in the background will degrade the system performance4. We cannot have an interactive process on the background because it will make the output of foreground and background process to be jumbled up.
04/22/23
11104/22/23Confidential © Tech Mahindra 2006
Process Oriented Utilities (Contd.)
1. & :This symbol has to be placed at the end of the
command, it indicates to execute the process in the background.
Syntax : <command/utilities> > <filename> &
Eg.: a. sort sort1 > sort1.out &
The above command will be executed in the
background. After the completion it will create a file named
sort1.out..
04/22/23
11204/22/23Confidential © Tech Mahindra 2006
Process Oriented Utilities (Contd.)
b. sort sort1 &The above command will be executed in the background.
Instead of redirecting the output to a file. It will display the sorted
contents of the file on the standard output device.
Note :1. After issuing the command succeeded by & sign. The shell displays the PID of the process. 2. The process/commands submitted using & sign in the background will get existed only for that session. (i.e., till we logout, once when the user logs out before the completion of the process that process will be terminated before closing the session).
04/22/23
11304/22/23Confidential © Tech Mahindra 2006
Process Oriented Utilities (Contd.)
2. nohup :It is an another method to submit the process/commands in the background. The difference is it will be executing even when the user logs out.Syntax : nohup <command/utilities>Eg.: a. nohup sort sort1The above command will be executed in the background. After the completion it will create a file named nohup.out. b. nohup sort sort1 > sort1.outThe above command will do the sorting process in the background and transfers the output to the file named sort1.out.
04/22/23
11404/22/23Confidential © Tech Mahindra 2006
Note :If more than one process has been submitted to the
background using nohup utility without the output file mentioned. The
output of the background process will be appended to
nohup.out in the sequence in which they have been submitted.
Process Oriented Utilities (Contd.)
04/22/23
11504/22/23Confidential © Tech Mahindra 2006
Process Oriented Utilities (Contd.)
What is the difference b/w submitting the process in the background using & and nohup command ?
& nohupThe process submitted using & will perform till that session gets expires.
The process submitted using nohup will get executed even after the session gets expires.
To transfer the output of the background process to a file, user has to represent explicitly
By default the output of the background process will be transferred to a file named nohup.out by default.
04/22/23
11604/22/23Confidential © Tech Mahindra 2006
Process Oriented Utilities (Contd.)
Process Priorities Priorities ranges from 0 to 39. 0 is the highest priority and 39 is the lowest. 20 is the default priority assigned to all the
processes. An ordinary user can only increment the value that is
he can only decrease his priority. Increasing that is decrementing the priority value can
be done only by the super user.Note :
The higher the priority value lower the preference to execute the process. As a normal user we can reduce the preference to execute the process.
04/22/23
11704/22/23Confidential © Tech Mahindra 2006
Process Oriented Utilities (Contd)
Changing the Process PrioritySyntax : nice <number> <commands>Eg.: a. nice -15 cat sort1The above command is used to increase the nice value of the command cat that makes the command to get the lowest priority. (i.e., 20 + 15 = 35). b. nice cat sort1The above command is used to increase the priority value 10 to the command cat. By default the value associated to nice command is 10. (i.e., 20 + 10 = 30).
04/22/23
11804/22/23Confidential © Tech Mahindra 2006
Note :1. The normal user can change the priority of the
process ranging from 0 to 19. 2. The user is forced to give only the positive
values, only the super user can give both positive and negative
values.3. By default the value associated to the nice
command is 10.
Process Oriented Utilities (Contd.)
04/22/23
11904/22/23Confidential © Tech Mahindra 2006
Scheduling of ProcessThere are three different types of command available to schedule the
user defined process they are at , batch, crontab (chronograph).
1. at :This command is used to execute Unix command at a future date and time.Syntax :a. at <time> <month> <date> b. at <time> <month> <date> < <file name>
Note :The process scheduled will always terminate with .a indicating that this job is submitted using at command
Process Oriented Utilities (Contd.)
04/22/23
12004/22/23Confidential © Tech Mahindra 2006
Eg.:a. at 17:00ls –alThe above command is used to execute the ls –al command at 5:00 pm on the current date. (Type ctrl d to exit thescheduling process using at command).b. at 15:00 jan 09 echo “ All the Best For Your First Quiz in Unix”The above command will be executed on 9th of January at 3:00 PM.c. at 19:00 jan 12 < submitThe above command will execute the commands available on the file named submit on 12th of January at 7:00 PM.
Process Oriented Utilities (Contd.)
04/22/23
12104/22/23Confidential © Tech Mahindra 2006
1. To list the Jobs submitted using at commandSyntax : at –lEg.: at -l
2. To Remove the Jobs Submitted Using at commandSyntax : at –r <processid>Eg.: at –r 74.a
Note :
This command will not be executed in Linux.
Process Oriented Utilities (Contd.)
04/22/23
12204/22/23Confidential © Tech Mahindra 2006
2. batch :The system decides the best time for
executing the commands. Unix executes our job when it is relatively free and the system load is light
Syntax :a. batchb. batch < <file name>
Note :The process scheduled will always
terminate with .b indicating that this job is submitted using batch command
Process Oriented Utilities (Contd.)
04/22/23
12304/22/23Confidential © Tech Mahindra 2006
Eg.:a. batchls –alThe system decides when to execute the above commandls –al (Type ctrl d to exit the scheduling process using batch command).b. batch < submitThe above command will execute the commands available on the file named submit based on the system performance.
Process Oriented Utilities (Contd.)
04/22/23
12404/22/23Confidential © Tech Mahindra 2006
3. crontab : ChronographIt can be used to specify the date and time for each command and they can also be carried out repeatedly without reissuing.
Syntax :
<Minute> <Hour> <Date> <Month> <DOW> <Command>
Eg.: 00 09 * * 1 echo “Salary Date ” ( Stored in cmdfile)
crontab cmdfile The above message will be displayed at 9:00 AM on every Monday.
Process Oriented Utilities (Contd.)
04/22/23
12504/22/23Confidential © Tech Mahindra 2006
Note :1. A * means all possible values. 2. Sunday is represented as 0 in the Day of week field.
When is the following mail sent? 30 08 01 * * mail user1<statusreport
The above command will be executed on 1st of every month at 08:30
AM.
Note : All these three commands (i.e., at, batch & crontab) can’t be implemented in LINUX operating system.
Process Oriented Utilities (Contd.)
04/22/23
12604/22/23Confidential © Tech Mahindra 2006
at batch crontabIt is used to schedule the process at a specified date and time. If the same job has to be processed the user has to explicitly issue this command.
It is used to execute the commands submitted to it based on the system performance.
It is same as that of at command. But the only difference is it can be carried out repeatedly for n number of times.
What is the difference b/w at, batch and crontab commands ?
Process Oriented Utilities (Contd.)
04/22/23
12704/22/23Confidential © Tech Mahindra 2006
Communication Utilities write mesg wall mail ftp telnet
04/22/23
12804/22/23Confidential © Tech Mahindra 2006
Communication Utilities (Contd.)
1. write :It can be used by any user to write something on
someone else’s terminal.
Syntax : write <username> <terminal name>Note :
1. The recipient must be logged in, else an error message is
displayed.2. The recipient must have given permission for
messages to reach his or her terminal.
04/22/23
12904/22/23Confidential © Tech Mahindra 2006
Communication Utilities (Contd.)
Eg.:a. write user2The above command is used to transfer the message to user named user2. (Provided the user2 has the message permission set to yes. If the user has the message set to no we will get a
message stating that permission denied).b. write user2 tty01The above command is used to transfer the message to the user named user2 on the terminal named tty01. (If user2 has logged in more than one terminal. The message will be sent only to the terminal named tty01).
04/22/23
13004/22/23Confidential © Tech Mahindra 2006
Communication Utilities(Contd.)
Command to see the write permission of the usersa. finger :
The above command is used to identify which are all the users connected and which, if any, can receive messages. It will have a * preceded by the terminal name indicates that the user has a message set to no.
b. who –T :It is also similar to that of finger
command. But the difference is it represents using + (Message to Yes) and - (Message to No).
04/22/23
13104/22/23Confidential © Tech Mahindra 2006
2. Setting Message Permissionmesg is a command used to set the message permission. If it has been
succeeded by y it represents yes , n represents no.Syntax : mesg <option> <y/n>Eg.:
mesg yThe above command is used to set message
settings as yes so that the particular user can send and
receive messages.
Communication Utilities(Contd.)
04/22/23
13204/22/23Confidential © Tech Mahindra 2006
3. wall : This command can only be used by the super user. Using wall command the super user can communicate to all the users connected to the system. It will be available in /usr/bin directory
Syntax : wallEg.: wallThe above command is used to transfer messages to all the users connected to the system irrespective of whether he sets the message to yes or no.
Communication Utilities(Contd.)
04/22/23
13304/22/23Confidential © Tech Mahindra 2006
4. mail : This command is used to transfer the messages
from one user to another user irrespective of whether he has logged in or not.a. To Send a mail
Syntax : i. mail <user1 . . .> Eg.:
i. mail mageshThe message will be sent to the user
named magesh. ii. mail magesh bms
The same message will be sent to the users
named magesh and bms.
Communication Utilities(Contd.)
04/22/23
13404/22/23Confidential © Tech Mahindra 2006
b. To read the mail Type mail at the prompt. This displays the list of mails. Now the prompt will be &. Type the message number to read the message.
Syntax: mail & <some number>
Eg.: mail
&3The above command will display the list of
mails available to the user. Then it will prompt with symbol & (mail prompt). The second line in the example is used to read the 3rd mail from the list.Note :
To come out of the mail prompt type q.
Communication Utilities(Contd.)
04/22/23
13504/22/23Confidential © Tech Mahindra 2006
4. telnet : telnet utility is used to connect to a remote machine telnet host address
telnet 172.21.102.7 Login name and password is required to login into a
remote system The processing is done by the remote machine and
the user’s machine just acts as a dumb terminal
Communication Utilities(Contd.)
04/22/23
13604/22/23Confidential © Tech Mahindra 2006
5. ftp : File Transfer Protocol Used to transfer files to and from a remote machine ftp can transfer binary and ASCII files
Syntax : ftp <remote machine address>
a. To Download the file from the remote machineget <remote-filename> <local-filename>
b. To Upload the file into the remote machine put <local-filename> <remote-filename>
Communication Utilities(Contd.)
04/22/23
13704/22/23Confidential © Tech Mahindra 2006
Things to know before using Unix editors.
/etc/termcap or /etc/terminfo file Contains the capabilities and codes of keys To control a large number of display terminals
Type Ahead Buffer.
Editors
04/22/23
13804/22/23Confidential © Tech Mahindra 2006
Editors. (Contd)
Type of editors available under UNIX Line editors
ed : UC Berkeley ex : Powerful than ed, Bell Systems
Screen editors vi (stands for visual) is the full screen editor vim - Vi Improved emacs (GNU’s)
04/22/23
13904/22/23Confidential © Tech Mahindra 2006
vi startup file .exrc
vi reads .exrc before loading and all options like map, abbr and set
These settings are permanent for a vi session Used to Customize the vi environment.
Editors. (Contd)
04/22/23
14004/22/23Confidential © Tech Mahindra 2006
Salient features of vi
Omnipresent in all UNIX systems. Fast. Customizable. Powerful UNDO features. Same key strokes can have more than one
meaning depending on current mode.
Editors. (Contd)
04/22/23
14104/22/23Confidential © Tech Mahindra 2006
Limitations of vi
No Error Messages will be displayed instead gives a beep sound.
No Online Help Case Sensitive
Editors. (Contd)
04/22/23
14204/22/23Confidential © Tech Mahindra 2006
Modes of Executions in vi
vi works in 3 different modes
Command mode : Keys are interpreted as commands
Insert mode : Keys echoed in edit buffer ex mode (esc colon :) : Keys interpreted as
commands of ex.
Note : Initially vi editor will open the information in command mode
Editors. (Contd)
04/22/23
14304/22/23Confidential © Tech Mahindra 2006
Vi operating modes
Command mode
Insert mode
i, I , o, O, a, A ..
esc
Exmode (:)
Enter :
Exit:q
Editors. (Contd)
04/22/23
14404/22/23Confidential © Tech Mahindra 2006
Editors. (Contd)
Command Mode Operations
Command Functionh Moves the cursor one character to
the leftl Moves the cursor one character to
the rightj Moves the cursor one line down
from the current positionk Moves the cursor one line up from
the current position+ Moves the cursor to the beginning
of the next line- Moves the cursor to the beginning
of the previous line
04/22/23
14504/22/23Confidential © Tech Mahindra 2006
Editors. (Contd)
Command Function0 Moves the cursor to the beginning of
the current line
$ Moves the cursor to the end of the current line
w Moves the cursor to the right, first character of the next word
b Moves the cursor to the left, first character of the previous word.
E Moves the cursor to the end of the current word.
Command Mode Operations
04/22/23
14604/22/23Confidential © Tech Mahindra 2006
Editors. (Contd)
Command FunctionH Moves the cursor to the first line on
the screenM Moves the cursor to the Middle line on
the screen
L Moves the cursor to the Last line on the screen.
G Moves the cursor to the beginning of the last line in the file
nG Moves the cursor to the beginning of the nth line specified
Note : All these commands can be activated in vi editor by pressing an Esc key followed by the character.
04/22/23
14704/22/23Confidential © Tech Mahindra 2006
Editors. (Contd)
Insert Mode Operations Command Function
i Enters Text input mode and inserts text at the cursor.
I Enters Text input mode and inserts text at the beginning of the current Line.
a Enters Text input mode and inserts text after the cursor.
A Enters text input mode and appends text at the end of current line
o Enters the text input mode by opening a new line immediately below the current line.
O Enters the text input mode by opening a new line immediately above the current line.
04/22/23
14804/22/23Confidential © Tech Mahindra 2006
Editors. (Contd)
Command Functionx Deletes the character at the
current cursor position.X Deletes the character to the left of
the cursor position.dw Deletes the word from the current
cursor positiondd Deletes the current line
d0 Deletes the part of the line before the current cursor position.
Insert Mode Operations
04/22/23
14904/22/23Confidential © Tech Mahindra 2006
Editors. (Contd)
Command Functiond$ Deletes the part of the line from the
current cursor position. (including the current cursor point)
nx, ndw,ndd Deletes n number of characters, words and lines continuously.
u To Recover the last deleted line
nu Recovers ‘n’ last deleted lines.
Insert Mode Operations
04/22/23
15004/22/23Confidential © Tech Mahindra 2006
Editors. (Contd)
Escape Mode Operations (:)Command Function
w Write the information on to the file and resume editing.
w! <file name>
Write the information on to the file mentioned on the escape mode
wq Save the information on to the file and exit vi editor
q Quits vi if changes made to the buffer were written to the file
q! Quit vi without making any changes to the file.
help Gives the help information about the vi editor
04/22/23
15104/22/23Confidential © Tech Mahindra 2006
Editors. (Contd)
Command
Function
m ,n d Deletes lines from m to n. (including both the lines)
n mo p Moves nth line to pth line.Eg.: 3 mo 7 ( Moves the third line to the seventh line)
m , n mo p
Moves lines m to n to pth line.Eg.: 3,5 mo 7 (Moves lines 3 to 5 to 7th line)
m co p Copies line m after line p Eg.: 3 co 7 (Copies 3rd line after 7th line)
m , n co p
Copies lines m to n after line pEg.: 3,7 co 12 (Copies from 3rd to 7th line after 12th line)
Escape Mode Operations (:)
04/22/23
15204/22/23Confidential © Tech Mahindra 2006
Editors. (Contd)
Command Functionm ,n w <filename>
Writes lines from m to n to a file.
m , n w >> <filename>
Appends lines from m to n to a file.
r <file name> Reads the contents of the filename at the current cursor position Eg.: :r grep1 (Reads the content of grep1 from the current cursor position of the opened file).
Escape Mode Operations (:)
04/22/23
15304/22/23Confidential © Tech Mahindra 2006
Editors. (Contd)
Command Functionabbr <abbreviation> <long form>
An abbreviation defined for a long form. When we type the abbreviation followed by a space, it is replaced by its long form.
una <abbreviation> Unabbreviates the abbreviation
abbr Lists the currently defined abbreviation.
Escape Mode Operations (:)
04/22/23
15404/22/23Confidential © Tech Mahindra 2006
Editors. (Contd)
Set Operations (:)
Command Functionset nu Set display of line numbers on.set nonu Set displays of line numbers off
(default).set showmode Displays mode in which we are
working (default).set shownomode
Do not display the current working mode.
set ic Ignore cases while searching for a pattern
set noic Do not Ignore case while searching a pattern (default)
04/22/23
15504/22/23Confidential © Tech Mahindra 2006
Editors. (Contd)
Command Functionset mesg Permits receipt of messages
from other terminalsset nomesg Don’t receive messages from
other terminals (default).set aw Automatically write buffer
contents to disk before switching to next file during multiple file editing.
set noaw Do not write buffer contents to disk before switching to next file during multiple file editing. (default).
set all Gives list of all setting possible
Set Operations (:)
04/22/23
15604/22/23Confidential © Tech Mahindra 2006
To Edit Multiple files in vi a. vi grep1 grep2 grep3
Used to display multiple files (Initially the editor will open the file grep1 and so on).
b. To Move to the next File:n It is used to open the next file mentioned in the vi (i.e., grep2):xn Used to open the xth file mentioned from the current file name associated with vi (i.e., 2n it opens the file named grep3)
c. To Open the First File:rew It is used to open the first file mentioned in the vi (i.e., grep1)
Editors. (Contd)
04/22/23
15704/22/23Confidential © Tech Mahindra 2006
d. :e <file>Directly lets u to switch to any file or even
open the one not listed in the args.Eg.: :e grep2 (Opens the file named
grep2)e. :f
Displays the name of the current file which is edited
Editors. (Contd)
04/22/23
15804/22/23Confidential © Tech Mahindra 2006
Search in vi (command mode) /xy All words containing xy either in the
beginning or middle or end. Eg. : xyz, , apxy and so on
/^xy A line beginning with xy
/xy$ A line ending with xy
/ \<xy All words starting with xy
Editors. (Contd)
04/22/23
15904/22/23Confidential © Tech Mahindra 2006
Summary History of UNIX Key features of UNIX UNIX System Architecture UNIX File System Processes in UNIX I/O Redirections File Security Some Basic Commands Utilities in UNIX
Text Processing,File Handling,Compression ,Communication & Process Orieneted
Editor Types of Editor vi startup process Features of vi Modes of vi Commands used in each and every mode