User Tools

Site Tools


wiki:2016moreless

WORKING WITH FILES

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:

  • Make a subdirectory within your 02_Exercises folder for today's work.
  • Using what you learned last week, make a copy of the directory you created for Assignment1 and place it in your 02_Exercises/160830 folder. Your command may look something like this:
$cp /~/LinuxClass/01_Assignments/Assignment1/S288C_reference_genome_R64-1-1_20110203 /~/LinuxClass/02_Exercises/160830/
  • Navigate into the subdirectory 01_genome.
  • Peek into the genome file there with more, less, head, and tail.
  • Next, navigate to ../03_annotations. Peek into the annotation file.

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 orf*.fasta
  161265  446990 11491336 orf_coding_all_R64-2-1_20150113.fasta
   60443  344987 5328465 orf_trans_all_R64-2-1_20150113.fasta
  221708  791977 16819801 total

To redirection

wiki/2016moreless.txt · Last modified: 2016/08/29 11:00 by erin