Unix commands allow me to navigate folders and inspect files using the Terminal. A command generally consists of a command name, optional flags that modify its behaviour, and arguments specifying the files or folders it should act on.
pwd prints the full path of the current working
directory. This helps me check my location before running commands.
pwd
ls lists the visible files and folders in the current
directory. The -l option displays more details, while
-a includes hidden entries. Options can also be
combined.
ls
ls -l
ls -a
ls -la
cd changes the working directory. A relative path starts
from my current location, whereas an absolute path starts from the
filesystem root. The shortcut .. means the parent
directory, and ~ represents my home directory.
cd ~/mb5370-workshops/command_line
pwd
# Move up one directory.
cd ..
# Return to the command_line folder.
cd command_line
Consistent filenames make project files easier to locate. Numeric
prefixes, such as 01_command_line.Rmd, keep workshop notes
in a clear sequence.
cat displays the contents of a text file in the
Terminal. It is useful for short files, but large sequence files can
produce too much output.
cat example.fasta
head displays the first ten lines by default. The
-n option specifies how many lines to show. This provides a
quick preview without printing the entire file.
head example.fasta
head -n 4 example.fastq
grep searches for a pattern and prints matching lines.
The -n option includes line numbers, while -i
makes the search case-insensitive. Quoting patterns helps prevent the
shell from interpreting special characters.
grep -n "ACGT" example.fasta
# Find FASTA headers: ^ means the beginning of a line.
grep "^>" example.fasta
man opens a command’s manual page, explaining its
purpose, options and usage. Within the manual viewer, I can scroll
through the documentation and press q to exit.
man ls
man grep
FASTA is a text format for nucleotide or protein sequences. Each
record begins with a header line starting with >,
followed by an identifier and an optional description. The sequence
appears on the following line or lines. FASTA does not store per-base
quality scores.
>sequence_1 example DNA sequence
ACGTTGCA
FASTQ stores sequence reads together with per-base quality scores. A typical unwrapped record contains four lines:
@.+.@read_1
ACGTTGCA
+
IIIIIIII
The sequence and quality strings must have the same length. FASTQ is commonly used for sequencing reads because it retains information about confidence in each base call.
Commands such as head help inspect the structure of
sequence files. However, previewing a few lines does not confirm that
the entire file is correctly formatted.