User Tools

Site Tools



Peeking inside files

There are four main commands for printing file contents to the screen…

more – scroll down through files
less – scroll up or down through files
head – show the top n lines. The default is n = 10
tail – show the bottom n lines. The default is n = 10

:!: Exercise:

  • Make an example file called file1.txt. Save some content in it.
  • Try the following ways of peeking into your file…
$ more file1.txt

Use spacebar or down arrow to scroll down
Type q to quit

$ less file1.txt

Use spacebar or down arrow to scroll down
Use b or up arrow to scroll up
Type q to quit

$ head file1.txt #show first 10 lines
$ head -n 5 file1.txt #show first 5 lines
$ tail file1.txt #show last 10 lines
$ tail -n 5 file1.txt #show last 5 lines

;-) Quick tip: Sometimes it looks like head or tail are showing way more lines than you expect. If your lines are very, very long (typical in bioinformatics), this may be due to forced word wrapping in the terminal. Try re-sizing your browser bigger or smaller to see if this is the case.

:!: Exercises:

  • Navigate into the directory 160825_options_ex.
  • Peek into the dm6_chrom_sizes.txt file with more, less, head, and tail.

Getting file info

One of the most handy commands for getting information about a file is word count.

wc <file.txt> …

Word count spits out:

  1. number of lines in the file
  2. number of words in the file
  3. number of characters/bytes in the file
  4. the file name
  5. some totals if multiple files are given.
$ wc dm6_chrom_sizes.txt
$ wc *.txt

Getting help

wiki/2018moreless.txt · Last modified: 2018/08/23 05:33 by erin