LINUX
COMMANDS
Contents | Previous
| Next
Viewing text files
$ head
head report.txt
View first 10 lines of the file, report.txt.
head -5 report.txt
View first 5 lines of the file, report.txt.
$ tail
tail weblog
View last 10 lines of the file, weblog.
tail -20 weblog
View last 20 lines of the file, weblog.
$ cat - concatenate
cat /etc/fstab
View all of file /etc/fstab.
cat a.txt b.txt > ab.txt
Append (concatenate) b.txt to a.txt and
redirect (>) result to ab.txt.
Intermediate tip:
You can also use cat on files in the /proc
directory to display information about your system. For
example, cat /proc/modules displays the kernel
modules loaded, and cat /proc/pci displays information
on your PCI devices. For further details, enter man
proc.
$ tac - reverse concatenate
tac log.txt
View all of file log.txt in reverse (last line
first to first line last).
$ less
less dirs.txt
View the dirs.txt file in the less program, allowing
you to view large files, line by line. (Press q
to quit.)
Note:
The more program allows you to view text screen
by screen, displaying at the bottom of the screen something
like '--More--(86%)' to indicate 86% of the text
has been viewed. The less program is the improved
more that allows you to scroll up and down, line
by line, using the cursor keys.
$ sort
sort list.txt
Display contents of list.txt file in alphabetical
order.
sort -r list.txt > sorted_list.txt
Same as above, but in reverse (-r) order, and output
result to file, sorted_list.txt.
Contents | Previous
| Next