Unix training session 2


Published on

Logging In to the System
File Comparison
Text processing
Symbolic and Hard Links
Text processing commands

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Unix training session 2

  1. 1. Presented by – Anil Kumar Kapil Anil Kumar Kapil Logging In to the System  File Comparison  Text processing  Symbolic and Hard Links  Text processing commands  February 7, 2014 UNIX
  2. 2. LOGGING INTO UNIX SYSTEM  User must have an account to use a Unix system  you must know two things before you can use the system: your user name and your password  You can only access the resources that are specified by your account information  Following are the possible errors while login to UNIX system     Login Incorrect No Shell No Directory Cannot Open Password File Anil Kumar Kapil There is at least one super user account in a system, usually named root, who has absolute power over the system. February 7, 2014 
  3. 3. FILE COMPARISON Diff Command  file comparison  displays two files and prints the lines that are different text files directory comparison  display files which are present in dir 1 and not in dir2 & vice -versa  Diff notation includes 2 numbers and a character between them. Characters tell you what kind of change was discovered:      Useful command line options for diff       d – a line was deleted c – a line was changed a – a line was added I – allows you to ignore case when comparing lines (aaa will equal AaA, etc) r – recursively compare directories (and any files found there) s – report identical files (you can script around this if your task is to confirm which files are identical) b – Ignores trailing blanks (spaces and tabs) and treats other strings of blanks as equivalent w –Ignore white space when comparing lines Example  Diff file1.txt file2.txt 1d0 < aaa This means that 1 line was deleted. < aaa suggests that the aaa line is present only in the original file 3c2 < ccc -->cc  And this means that the line number 3 has changed 7a7 > hhh  one new line appeared in the second file, it's "hhh" in the line number 7 February 7, 2014 
  4. 4. FILE COMPARISON February 7, 2014  Diff3  for comparison of 3 files  diff3 file1 file2 file3  Comm   Cmp  The cmp command compares the contents of two non text files (executable files)  Example : cmp new_prog1 old_prog1 Output : new_prog1 old_prog1 differ: byte 6, line 1
  5. 5. HARD LINKS AND SOFT LINKS Link  Every file has a data structure (record) known as an I-node that stores information about the file, and the filename is simply used as a reference to that data structure. A link is simply a way to refer to the contents of a file. There are two types of links:  Hard link  pointer to the file's i-node    original filename and the linked filename point to the same physical address and are absolutely identical A directory cannot have a hard link It is possible to delete the original filename without deleting the linked filename. Example : ln a-file.txt b-file.txt February 7, 2014 
  6. 6. HARD LINKS AND SOFT LINKS Soft links (symbolic links): file that contains the name of another file.     Symbolic link is like a pointer to the pointer to the file's contents. You may remove the original file but it will cause the linked filename to be there, but without any data You should be careful about symbolic links. If you are not, you will be left with files that do not point anywhere because the original file has been deleted or renamed it can be used to link directories as well as files Example : ln -s a-file.txt b-file.txt February 7, 2014 
  7. 7. TEXT PROCESSING COMMANDS echo  sort: sort command sort the lines of a file or files, in alphabetical order Example:  sort file.txt  sort -r file.txt  sort –f file.txt  sort –n file.txt  sort -k3 file.txt  cut: selects a list of columns or fields from one or more files    -- display in reverse order -- ignore case -- numerical order -- Sorts using the third field of each line cut –d ‘ ‘ -f 1,2,11, 15-20 file.txt cut –c 1-8 file.txt  it will extract first 8 characters of every line in the file. uniq: removes duplicate adjacent lines from sorted file while sending one copy of each second file Examples  sort names | uniq -d  will show which lines appear more than once in names file Options: -c print each line once, counting instances of each. -d print duplicate lines once, but no unique lines.  -u print only unique lines    tee: Put output on screen and append to file Examples  who | tee -a > <file> February 7, 2014 
  8. 8. February 7, 2014 Anil Kumar Kapil QUESTIONS ?
  9. 9. February 7, 2014 Anil Kumar Kapil Thank You ……