What is the shell command to display contents of a file?

76

10

Like that of .txt or .html

King of Zhopa

Posted 2010-02-23T08:14:09.210

Reputation:

Answers

90

easiest are cat, head, tail, tac (for reverse output)

less and more let you scroll the text files (less being more powerful)

you can also use text editors like nano, pico, vi, emacs

knittl

Posted 2010-02-23T08:14:09.210

Reputation: 3 452

1"less is more", no not really, but still funny. – Jim Aho – 2017-12-14T10:12:49.337

1For novice users, it really isn't funny. Glib, and annoying. – Richard Ev – 2018-06-19T04:49:31.810

14

cat and less are good for this.

Ignacio Vazquez-Abrams

Posted 2010-02-23T08:14:09.210

Reputation: 100 516

11

To Display the contents of a file use this command:

cat

Code:
cat test.txt

Malcolm

Posted 2010-02-23T08:14:09.210

Reputation:

8

you can use cat, although its really meant for concatenation of files. more or less are 2 other tools you can use. Other's include awk, eg using awk

$ awk '1' file

using sed

$ sed -n '1,$p' file

using grep

$ grep "." file

using head/tail to display some parts of the file

$ head -1000 file
$ tail -1000 file

Tools aside, you can also use just the shell to display your file

#!/bin/bash
while read -r line
do
  echo "$line"
done <"file"

user31894

Posted 2010-02-23T08:14:09.210

Reputation: 2 245

4

Try cat , head or tail.

Tim Post

Posted 2010-02-23T08:14:09.210

Reputation: 851

3

For viewing HTML files you can also use lynx, links, elinks or w3m which are text-mode browsers. They can also be used to view .txt files.

Paused until further notice.

Posted 2010-02-23T08:14:09.210

Reputation: 86 075

2

Or, less or more. See the man pages for more information. :)

Tom

Posted 2010-02-23T08:14:09.210

Reputation: 283

2

file : Display the type of file cat : Display the content of the file and outputs it on stdout.

You can use vi, emacs command to edit the file in Unix environment. If you do not have expertise in using vi/emacs you might find it little difficult to edit the file.

If you have X11 enabled, You can use a number of Linux editors like gvim, kate, kwrite, kdevelop etc.

Kwrite is my personal favorite in Linux.

www.sapnaedu.in

Posted 2010-02-23T08:14:09.210

Reputation: 289

1

cat Works fine with txt or html. (or less or more if you want tosee it page by page) or any text ediotr... (vi, emcas, gedit...).

Also know that if it's a binary file it's may contain control char that will do some displeasing things with your terminal (like changing charset). If that happen use reset to put it back in sane state.

You can also use file on file before displaying it's content, the system will guess it's type (based on content not filename name) and show it to you.

kriss

Posted 2010-02-23T08:14:09.210

Reputation: 221