codex-lv2-may-2025

Navigation

1 | 2 | 3 | 4 | 5 | 6 | Current Level: 7


Lesson: Work with Multiple Files Using Wildcards and Patterns


Objective

Learn how to copy, move, and list multiple files efficiently using wildcards and filename patterns in the Unix shell.


Step 1: Copy Multiple Files at Once


Step 2: Use Wildcards to Match File Patterns


Step 3: Match a Specific Pattern

Given a directory of .pdb files, which of the following commands list ethane.pdb and methane.pdb?

ls *t*ane.pdb
ls *t?ne.*
ls *t??ne.pdb
ls ethane.*

Try each one to see which patterns match.


Step 4: Help Organize and Copy Files Using Wildcards

Sam wants to organize a set of dated .txt files. She uses wildcard patterns to copy selected files into subdirectories:

cp *dataset* backup/datasets
cp *calibration.txt backup/calibration
cp 2015-11-23-* send_to_bob/all_november_files/
cp *10-23-dataset* send_to_bob/all_datasets_created_on_a_23rd/
cp *11-23-dataset* send_to_bob/all_datasets_created_on_a_23rd/

Step 5: Move Files into Organized Folders

Jamie has disorganized files:

ls -F
# analyzed/  fructose.dat  raw/  sucrose.dat

To tidy up:

mv fructose.dat sucrose.dat analyzed/

Now:

ls -F
# analyzed/  raw/

ls analyzed
# fructose.dat  sucrose.dat

Step 6: Reproduce a Folder Structure for a New Experiment

Goal: Copy folder structure (not files) from 2016-05-18 to 2016-05-20.

Best command:

mkdir -p 2016-05-20/data/raw
mkdir -p 2016-05-20/data/processed

Other options (multi-line versions) also work, but are more verbose:

mkdir 2016-05-20
mkdir 2016-05-20/data
mkdir 2016-05-20/data/raw
mkdir 2016-05-20/data/processed

Reflection Questions


Navigation

1 | 2 | 3 | 4 | 5 | 6 | Current Level: 7