1 / 35

UNIX OS

UNIX OS. DAY – 1 Session – 2. Objectives. Identify the standard input, output and error files Use input, output & error redirection Use of Pipes & tee command Hard Link & Soft Link. Objectives (contd.). Text manipulation command head, tail, cut, paste, sort & tr

kosey
Télécharger la présentation

UNIX OS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UNIX OS DAY – 1 Session – 2 MBT – NCS UNIX OS

  2. Objectives • Identify the standard input, output and error files • Use input, output & error redirection • Use of Pipes & tee command • Hard Link & Soft Link © CMC Limited A TATA Enterprise

  3. Objectives (contd.) • Text manipulation command head, tail, cut, paste, sort & tr • File Access Permission (FAP) command chmod, chown, chgrp • Locating a file using the find command • The vi editor to create & manage document files © CMC Limited A TATA Enterprise

  4. Standard Files • Standard Input File • The keyboard is referred to as the standard input file • In Unix, all open files, including the standard files, are assigned a number called the file descriptor. The file descriptor 0 (zero) is assigned to the standard input file © CMC Limited A TATA Enterprise

  5. Standard Files (contd.) • Standard Output File • The monitor is referred to as the standard output file • The file descriptor 1 is assigned to the standard output file © CMC Limited A TATA Enterprise

  6. Standard Files (contd.) • Standard Error File • The monitor is also the standard error file • The file descriptor 2 is assigned to the standard error file. © CMC Limited A TATA Enterprise

  7. Redirection Redirection changes the assignment for standard input, output & error • Input Redirection • The following examples illustrate the use of input redirection $ cat < test1 $ cat 0< test1 • Output Redirection • The following example illustrate the use of output redirection $ cat test1 > test2 $ cat test1 1> test2 $ cat test2 >> test1 ( >> is equal to append ) © CMC Limited A TATA Enterprise

  8. Redirection (contd.) • Error Redirection • The following example illustrate the use of error redirection $ cat datafile 2> error-mesg © CMC Limited A TATA Enterprise

  9. Pipe • Pipes are used to connect to streams • Syntax : command | command #The vertical bar ( | ) • It indicates to the shell that the output of the command before ‘|’ is to be send as an input to the command after it • The following example illustrate the use of pipe : • Without a pipe: $ ls – l > listoffiles $ less listoffiles • With a pipe: $ ls – l | less © CMC Limited A TATA Enterprise

  10. tee command • A tee command takes standard input, writes to standard output & to file(s). • Syntax: command | tee filename • The following example illustrate the use of tee command: Without a tee command: $ ls -l > listoffiles $ cat listoffiles • With a a tee command: $ ls –l | tee listoffiles © CMC Limited A TATA Enterprise

  11. Links • A link allows a file to have more than one name and yet maintain a single copy • Changes to one file will reflect in the other • Links are of two types : hard link & soft link (symbolic link) © CMC Limited A TATA Enterprise

  12. Hard Link • To create a hard link the command is ln filename1 filename2 • The inode number for filename1 & filename2 is same. © CMC Limited A TATA Enterprise

  13. Soft link (Symbolic link) • A soft link extends to different file systems. • A soft link links to a directory. • Soft links takes a different inode number then the actual file. • To create a hard link the command is ln -s filename1 filename2 © CMC Limited A TATA Enterprise

  14. Text manipulation commands • head command – allows the user to see the first few lines of the file. Syntax : head option filename • tail command – allows the user to see the last few lines of the file. Syntax : tail option filename • cut command – allows the user to slice the file vertically. Syntax : cut option filename • paste command – allows the user to concatenate the file vertically. Syntax : paste option filename © CMC Limited A TATA Enterprise

  15. Sort command • Sorts the data of the file. • It allows checking of field orders • It sorts the data on ASCII code sequences • Syntax: sort option –o output file data file © CMC Limited A TATA Enterprise

  16. Sort options © CMC Limited A TATA Enterprise

  17. Sorting (contd.) • Sorting on secondary key eg: sort –t “|” +2 –3 +1 filename -- This will sort the file on primary field 2 and secondary field 1. The –3 means where to stop sorting. • Sorting on columns in the fields eg: sort –t “|” +4.6 –4.8 filename -- This will sort the on the 2 characters from 6 to 8 in the fourth field. © CMC Limited A TATA Enterprise

  18. tr command • It is a filter that manipulates individual characters in a file. • Syntax : tr option expression1 expression2 standard input • The input is from standard input and not from the file. • Eg: tr ‘|/’ ‘,-’ < filename --- replace all | & \ with , & - tr ‘[a-z] ‘ ‘[A-Z]’ < filename --- replace all a-z with A-Z © CMC Limited A TATA Enterprise

  19. tr options • -d ‘’ - delete character Eg: tr –d ’|’ < filename • -s ‘’ – squeeze Eg: tr –s ‘ ‘ < filename d © CMC Limited A TATA Enterprise

  20. File Acces Permission (FAP) • File Access Permission (FAP) refer to the permissions associated with a file with respect to the following: • The mode of the file • The file owner • The group owner • The other users © CMC Limited A TATA Enterprise

  21. Assigning Permission to the File • The chmod command • Syntax : chmod mode file/directory • The chmod command is used to change the permissions associated with a file/directory © CMC Limited A TATA Enterprise

  22. Absolute modes with chmod © CMC Limited A TATA Enterprise

  23. Relative modes with chmod © CMC Limited A TATA Enterprise

  24. chown command • chown command is used to change the owner of the file. This command is irreversible. • Syntax: chown owner filename/directory © CMC Limited A TATA Enterprise

  25. chgrp command • chgrp command is used to change the group of the file. This command is irreversible. • Syntax: chgrp owner filename/directory © CMC Limited A TATA Enterprise

  26. Locating a file • The find command • Syntax: find option path • The find command is used to locat a file in a particular directory and its sub-directories. It is th most commonly used command for locating files anh has various option for advanced searches © CMC Limited A TATA Enterprise

  27. Editors • A text editor is used to create & manage text files & document. An editor is an application software that is usually bundled with an OS • Functions of an Editor • Create a file • Open an existing file • Copy & Pate text • Search for text • Handle a large amount of data © CMC Limited A TATA Enterprise

  28. The vi editor • The vi editor is a visual editor used to create and edit a text file, documents & programs. In Unix vi is a symbolic link to the vim editor, which is an imporved version of vi editor. • Getting started with vi • The vi editor is invoked by the following command at the Unix prompt vi filename © CMC Limited A TATA Enterprise

  29. The vi Editor (contd.) • vi is the screen editor. • It works in three modes – command, text, escape. • In the command mode the cursor movements can be handled. • In text mode the insert, append, change, open of text operation are handled. • In ex mode text search, changing visual interface, saving & quitting is handled. © CMC Limited A TATA Enterprise

  30. Summary • You can redirect input, output & errors to a file other than the standard files by the file descriptors along with the redirection symbols < , > and >>, 2> • A pipe is a feature through which standard output of a command or user program can be sent as the standard input to another command or user program • A tee command takes standard input & writes to standard output & to file(s) © CMC Limited A TATA Enterprise

  31. Summary (contd.) • A link allows a file to have more than one name and yet maintain a single copy, there are 2 types of links hard & soft • Text manipulation commands head, tail allows horizontal slicing of file whereas cut and paste command allows vertical slicing of file(s) • sort command sorts the data of the file. © CMC Limited A TATA Enterprise

  32. Summary (contd.) • tr is a filter that manipulates individual characters in a file. • File Access Permission (FAP) command chmod, chown, chgrp are used to manipulate files & direcories • To locate a file find command is used. • The vi editor is used to create and edit documents © CMC Limited A TATA Enterprise

  33. Recall • Recall © CMC Limited A TATA Enterprise

  34. Assignments • Day 1 Session 2 Assignments © CMC Limited A TATA Enterprise

  35. END of DAY 1/SESSION - 2 MBT – NCS UNIX OS

More Related