A short overview on Linux-commands to view and work with text files.
less – view text files
Less is a program to view text files. It is similar to more – but more powerful. Less allows backward movement in the file as well as forward movement.
Note that less can efficiently handle large input files, because it does not have to read the entire input file before starting.
less FILE
Commands which can be used within the program:
- /SEARCH_TERM: search for SEARCH_TERM in text
- n: jump to the next occurrence of the search term
- Shift + n: jump to the previous occurrence of the search term
cat – concatenate files
This command concatenates files and prints them on the standard output.
cat FILE_1 FILE_2 ...
head – print first lines of a file
To print the first LINES lines of file FILE (by default, the first 10 lines are shown) execute:
head -nLINES FILE
tail – print last lines of a file
To prints the last LINES lines of file FILE (by default, the last 10 lines are shown)execute:
tail -nLINES FILE
With tail you can watch a file while it is growing:
tail -f FILE
nl – line numbers
nl prints the content of file FILE with line numbers:
nl FILE
wc – count in a file
wc can be used to print newline, word, and byte counts for each file.
If more than one file is specified, a line summing up the statistics of the individual files is added.
wc FILE
Compare files
- diff: compare files line by line
- comm: compare two sorted files line by line
- cmp: compare two files byte by byte
sort – sort lines of a text file
Sort sorts the lines of a text file and sends them to standard output:
sort FILE