I always say you don't need to use the command line to use Linux effectively—I know many Linux users who never crack open a terminal window and are quite happy. However, even though I don't consider myself a techie, I spend about 20% of my computing time at the command line, manipulating files, processing text, and using utilities.
One thing I often do in a terminal window is viewing files, whether text or word processor files. Sometimes it's just easier to use a command line utility than to fire up a text editor or a word processor.
Here are three of the utilities I use to view files at the command line.
less
The beauty of less is that it's easy to use and it breaks the files you're viewing down into discrete chunks (or pages), which makes them easier to read. You use it to view text files at the command line, such as a README, an HTML file, a LaTeX file, or anything else in plaintext. I took a look at less in a previous article.
To use less, just type:
less file_name
Scroll down through the file by pressing the spacebar or PgDn key on your keyboard. You can move up through a file by pressing the PgUp key. To stop viewing the file, press the Q key on your keyboard.
Antiword
Antiword is great little utility that you can use to that can convert Word documents to plaintext. If you want, you can also convert them to PostScript or PDF. For this article, let's just stick with the conversion to text.
Antiword can read and convert files created with versions of Word from 2.0 to 2003. It doesn't read DOCX files—if you try, Antiword displays an error message that what you're trying to read is a ZIP file. That's technically correct, but it's still frustrating.
To view a Word document using Antiword, type the following command:
antiword file_name.doc
Antiword converts the document to text and displays it in the terminal window. Unfortunately, it doesn't break the document into pages in the terminal. You can, though, redirect Antiword's output to a utility like less or more to paginate it. Do that by typing the following command:
antiword file_name.doc | less
If you're new to the command line, the | is called a pipe. That's what does the redirection.
odt2txt
Being a good open source citizen, you'll want to use as many open formats as possible. For your word processing needs, you might deal with ODT files (used by such word processors as LibreOffice Writer and AbiWord) instead of Word files. Even if you don't, you might run into ODT files. And they're easy to view at the command line, even if you don't have Writer or AbiWord installed on your computer.
How? With a little utility called odt2txt. As you've probably guessed, odt2txt converts an ODT file to plaintext. To use it, run the command:
odt2txt file_name.odt
Like Antiword, odt2txt converts the document to text and displays it in the terminal window. And, like Antiword, it doesn't page the document. Once again, though, you can pipe the output from odt2txt to a utility like less or more using the following command:
odt2txt file_name.odt | more
Do you have a favorite utility for viewing files at the command line? Feel free to share it with the community by leaving a comment.
2 Comments