guest@linuxthings:~/guides$ man viewing
File Viewing
Tools to examine file contents without editing.
cat (Concatenate)
cat file
cat -n file # Number output lines
cat -b file # Number only non-blank lines
cat -s file # Squeeze runs of blank lines into one
cat -A file # Show tabs (^I), line ends ($) and other hidden characters
cat file1 file2 > newfile # Join files
tac file # Print lines in reverse order (handy for logs)
nl file # Number lines, with more control than cat -ncat -A is a quick way to spot Windows line endings, which show up as ^M before the $.
less
A pager program. Allows scrolling through long files.
Key | Action |
|---|---|
Space or f | Page down |
b | Page up |
Enter | Down one line |
g / G | Jump to the start / end of the file |
/pattern | Search forward |
?pattern | Search backward |
n / N | Next / previous match |
F | Follow new lines as they are added (like tail -f) |
v | Open the file in your default editor |
h | Help |
q | Quit |
less hugefile.txt
less -N file # Show line numbers
less -S file # Chop long lines instead of wrapping
dmesg | less # Page through any command's outputhead & tail
head file # First 10 lines
head -n 5 file # First 5 lines
head -c 100 file # First 100 bytes
tail -n 5 file # Last 5 lines
tail -n +20 file # Everything from line 20 onwards
tail -f /var/log/syslog # Follow file changes in real-time
tail -F app.log # Keep following even if the file is rotated or recreated
ls -lt | head # The 10 most recently modified filesPress Ctrl+C to stop tail -f.
Compressed Files
zcat file.gz # Print a gzip-compressed file
zless file.gz # Page through it
zgrep error log.gz # Search inside itBinary Files
file mystery # Identify a file's type from its contents
strings program # Print readable text embedded in a binary
od -c file # Dump bytes as characters and escapes
xxd file | less # Hex dump with an ASCII column