CLI Introduction Exercises
These exercises accompany the Introduction to BASH module. They alternate between hands-on practice and knowledge checks.
Exercises developed by Kristine Lacek
Exercise 1 — Manual, Flags, and Arguments
View the full manual for each of these commands by running man <command>.
Get quick help with the flags for each command by running <command> --help.
lssortheadvimdatetime
Question:
Which of the commands listed above (ls, sort, head, vim, date, time) is a text editor?
Question:
Which of the commands listed above does not have a manual entry (via man)?
Exercise 2 — Command Line Navigation
Complete the following steps in order:
- Open your terminal.
- Change directory to your home directory (
~). - List the contents of that directory.
- Make a directory within your home directory called
2026-BIFX-TRAINING. cdto that new directory you just made.- Using
.., cd back “up” to your home directory. - Try tab-complete: start the command
cd 2026-then press Tab to complete the full directory name. - Try using your history: using only the up arrow to move through your recent commands, re-run the command you ran for step 2.
Question:
What command changes directory to your home directory?
Question:
What command creates a new directory called 2026-BIFX-TRAINING?
Exercise 3 — Network and Downloads
Download the samplesheet from the workshop website for the next practical.
Linux/WSL (wget):
wget https://raw.githubusercontent.com/CDCgov/id-bioifx-workshop/refs/heads/main/practical/samplesheet.csv
macOS / Unix:
macOS does not come with wget pre-installed, but you can install it with Homebrew. Homebrew is a package manager for macOS that simplifies the installation of software.
# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install wget
brew install wget
wget https://raw.githubusercontent.com/CDCgov/id-bioifx-workshop/refs/heads/main/practical/samplesheet.csv > samplesheet.csv
Exercise 4 — File Viewing and Manipulation (Part 1)
- Ensure your
samplesheet.csvdownloaded properly withcat. - Copy your samplesheet using
cpto makesamplesheet_copy.csv. - Rename your
samplesheet_copy.csvtosamplesheet2.csvusingmv. - Using
tail, output the last 20 lines of your samplesheet, and using redirect (>), write them to another file calledsamplesheet_subset.csv. - Using
headand then piping intotail, output only the 8th line ofsamplesheet.csv. - Sort the samplesheet according to sample ID, numerically, then redirect to a file called
samplesheet_sorted.csv.
Question:
What command outputs the last 20 lines of samplesheet.csv and writes them to samplesheet_subset.csv?
Question:
What command using head piped into tail outputs only the 8th line of samplesheet.csv?
Question:
What command sorts samplesheet.csv numerically and redirects to samplesheet_sorted.csv?
Exercise 5 — File Viewing and Manipulation (Part 2)
cat samplesheet_sorted.csvto append tosamplesheet2.csv. Catsamplesheet2.csv— it should look twice as long!cat samplesheet_sorted.csvto overwritesamplesheet2.csv. Catsamplesheet2.csv— it should look just likesamplesheet_sorted.csv.- Rename
samplesheet2.csvback tosamplesheet_copy.csv. - Using
rmand glob (*) remove bothsamplesheet_copy.csvandsamplesheet_sorted.csvwithout removingsamplesheet.csv.
Question:
What operator appends output to an existing file (without overwriting)?
Question:
What operator overwrites a file with new output?
Question:
What command removes samplesheet_copy.csv and samplesheet_sorted.csv using a glob, without removing samplesheet.csv?
Exercise 6 — Searching and Text Processing (Part 1)
- Using
wconsamplesheet.csv, how many lines are there? - Using
wconsamplesheet.csv, how many characters are there? - Using
cutonsamplesheet.csv, output only the Barcode # field. - Make a file called
sample_list.txtby cutting and redirecting unique sample IDs from your fastqs. - Bonus: Using
trandsortonsamplesheet.csv, output the highest barcode number only (no “barcode”).
Question:
What command counts only the number of lines in samplesheet.csv?
Question:
What command counts the number of characters in samplesheet.csv?
Exercise 7 — Searching and Text Processing (Part 2)
Download the influenza FASTA file:
wget https://raw.githubusercontent.com/CDCgov/id-bioifx-workshop/refs/heads/main/practical/influenza.fasta
- Using
grepwith a flag or piping intowc, how many times does the sequenceGGGGCGGGG(4G 1C 4G) appear in yourinfluenza.fasta? - Using
grepwith the-Aflag (--helpif you don’t recall what that does), output all theA_HA_H1sequences to a file calledH1_HA.fasta.
Question:
What command counts how many times GGGGCGGGG appears in influenza.fasta?
Exercise 8 — Searching and Text Processing (Part 3): sed
Now we will use sed to turn our H1_HA.fasta headers into strain names:
sed -s "s/find/replace/g"
Goal: >3004125441_N8KIRZTI_v1 | A_HA_H1 → >A/Country/3004125441_N8KIRZTI_v1/2026
Complete the following parts:
- Part 1: Use
sed -sto remove the lines with two dashes (--) from grep output, redirect toH1_HA_1.fasta.- Find:
--→ Replace: nothing
- Find:
- Part 2: Use
sed -sto replace>with>A/Country/inH1_HA_1.fasta, redirect toH1_HA_2.fasta.- Since the replacement contains
/, you will need to use another delimiter character (%,#) for your sed.
- Since the replacement contains
-
Part 3: Use sed -sto replace `A_HA_H1 with/2026inH1_HA_2.fasta, redirect toH1_HA_3.fasta`.- Again, use an alternative delimiter since the replacement contains
/.
- Again, use an alternative delimiter since the replacement contains
- Part 4: Rename
H1_HA_3.fastatoH1_HA_final.fasta.
Intermediate challenge: Can you do this all in one command using multiple sed commands with pipe |?
Question:
When your find or replace string contains /, what alternative delimiter characters can you use with sed?
Exercise 9 — Compression and Archives
Download, uncompress, and re-compress the following files:
-
wget https://raw.githubusercontent.com/CDCgov/id-bioifx-workshop/refs/heads/main/practical/2012704893_273083_v1_H3_PCR_original_R1_001.fastq.gz wget https://raw.githubusercontent.com/CDCgov/id-bioifx-workshop/refs/heads/main/practical/2012704893_273083_v1_H3_PCR_original_R2_001.fastq.gz
Use ls -lah (the -h flag makes file sizes human-readable) to display the file sizes before and after compression.
Question:
What command uncompresses a .gz file?
Question:
What command compresses a file with gzip?
Exercise 10 — Permissions and Ownership
- Using
wget, pull downpermissions.txtat:
https://raw.githubusercontent.com/CDCgov/id-bioifx-workshop/refs/heads/main/practical/permissions.txt cat permissions.txt.- Using
chmod, remove read permissions for owner onpermissions.txt. cat permissions.txt— what does it say now?- Using
chmodagain, add read permissions back topermissions.txt. - Using the up arrow to load your last
wgetcommand, pull downpermissions.shby changing the command’s final.txtto.sh.
Question:
What chmod command removes read permission for the owner on permissions.txt?
Question:
What chmod command adds read permission back for the owner on permissions.txt?