# NSCI 580A4 fall 2017

### Sidebar

NSCI 580A4

Instructors
Tai Montgomery
Erin Nishimura

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:

• Navigate into the directory 160825_options_ex. (If you don't have this directory, download and un-package this file to create it: 160825_options_ex.tgz
• 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

Obtain files for next 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/