180 likes | 290 Vues
Workbook 8. Chapters 5-9. Introduction. In Linux (like Unix before it), nearly all configuration information is stored in text files. Contrast this with Windows, which stores configuration information in a huge, monolithic database called The Registry.
E N D
Workbook 8 Chapters 5-9
Introduction • In Linux (like Unix before it), nearly all configuration information is stored in text files. • Contrast this with Windows, which stores configuration information in a huge, monolithic database called The Registry. • Text files are generally easier to set up and work with. • Linux includes a rich set of tools for viewing and editing text files. The following chapters describe some of these.
Chapter 5: cut and paste commands • cut: selects columns of text in a text file. • Commands like head, tail, and grep can be considered to make “horizontal” cuts in a file. • cut can be considered to make “vertical” cuts in a file.
Switches for the cut command • Select character columns with the –c switch. • Select fields with the –f switch. • Select bytes with the –b switch (essentially the same as –c in most circumstances). • Specify the field delimiter character with the –d switch (tab is default).
Example 1 List files with a .txt “extension” with inodes: Show only inodes, owner, and file name:
Example 2 Look at the last 5 lines of /etc/passwd: Pick out user ID number, user ID, and name: Note the fields are in the original order, in spite of the order we requested them!
The paste command • Appends files horizontally, line by line • Example: put user ID number, user ID, and user name in the order we want them:
Chapter 6: the diff command • Compares two files, and reports the differences between them. • Example: modifying user data.
More switches • diff can be quite picky, and report all sorts of changes which are trivial and ultimately meaningless. Here are some switches to ease the pain:
Chapter 7: the tr command • Performs character translations (substitutions, deletions, squeezing) on the input stream and passes the modified string to the output stream. • Example 1: substituting characters
Example: deleting characters All spaces have been deleted.
Example: squeezing characters Fields are now separated by a single space.
Chapter 8: the aspell command • aspell is used for spell-checking text files. • Example:
Using aspell • aspell can be used on the stdin and stdout streams as illustrated in the previous example. • It can also be used to start an interactive spell check session: aspell –c filename • This will highlight any word it can’t find in the dictionary in turn, and offer you a range of alternatives for correction. • As usual, if there are no misspelled words, it says nothing at all.
aspell dictionaries • Two dictionaries are used by default: • The system-wide master dictionary in /usr/share/dict • A user-specific dictionary stored in.aspell.en.pws • A list of corrections made is kept in .aspell.en.prepl. • Note: the .en. refers to English; other languages can be used as well.
Chapter 9: fmt and split commands • The fmt command is generally used to break long lines up into shorter ones by inserting newline characters. • The split command is used to split large files into a set of smaller files with a common prefix.
Conclusion • Linux includes many commands for viewing, formatting, and manipulating text files. • This is useful, because nearly all configuration information is stored in text files. • This rich set of text editing tools helps system administrators maintain their Linux system.