Lab 6 - Working With Wildcards
A Brief description of the wildcards.
Cheat Sheet here
Video here
Note: Wildcards are all about pattern matching. They can be confusing but once you get a hold of them, you will never forget them. The table above gives you a summary of each wildcard. The goal of this lab is to give you enough practice for you to master wildcards in their basics form. Wildcards are very powerful because they can be combined to match pretty much any pattern that you can think of.
IMPORTANT!!! READ ME!!!!!
Before working on this lab, run this command:
curl https://cis106.com/assets/lab6.sh | bash
This will create a directory calledlab6
in your home directory
Question 1 | Using the * Wildcard
In your home directory, you should have a directory called
lab6
, if you don’t have it, make sure to run the curl command in theREAD ME
part of this lab.
- List all the
log
files located in thelab6
directory.- Create a directory called
log-files
inside thelab6
directory. Move all the log files to thelog-files
directory.- List all the configuration files in the
etc
directory. (Configuration files have the extension of .conf)- Long list all the configuration files in the
etc
directory that start with letterh
or letterp
sorted by file size. Modify the ls command with the proper options so that the output looks like this: (Notice the date)-rw-r--r-- 1 7.5K 08/19/21 /etc/pnm2ppa.conf
You can see a full list of control characters for the date here
Take a screenshot of your terminal showing all the commands that you used to complete this question.
Question 2 | Using the ? wildcard
- List only the hidden files inside the
lab6
directory. - List all the files with a 2 letter file extension in the
lab6
directory - Inside the
lab6
directory, list all the files that start with letterl
, have one character after letterl
, and the lettersst
. The the rest of the file name is irrelevant. - Inside the
lab6
directory, list all the files that have an_
and two characters before the file extension.
Take a screenshot of your terminal showing all the commands that you used to complete this question.
Question 3 | Using the [] Wildcard
- List all the files that start with an uppercase letter
- List all the files that start with an uppercase letter or a number
- List all the files that have a number in the file name
- List all the files that start with a lowercase letter and have a number before the file extension.
Take a screenshot of your terminal showing all the commands that you used to complete this question.
Question 4 | Using brace expansion.
The curly braces are not a wildcard but they are equally useful. The curly braces allow you to generate arbitrary strings to use with commands.
Problem 1:
In the lab6
directory, create the following directory structure. Display a tree of the directory. Take a screenshot:
wallpapers/
└── cars
├── 1080p
├── 2k
└── 4k
Problem 2:
Clear your terminal. in the lab6
directory, create the following directory structure. Display a tree of the directory. Take a screenshot:
assets/
├── imgs
│ ├── large
│ └── small
└── video
├── large
└── small
Problem 3:
Clear your terminal. in the lab6
directory, create the following directory structure. You need to create the pdf files as well. Remember mkdir creates directories while touch creates files. Display a tree of the directory. Take a screenshot:
docs/
└── books
├── history
│ ├── fall
│ │ └── book.pdf (this is a file not a directory)
│ └── spring
│ └── book.pdf (this is a file not a directory)
└── math
├── fall
│ └── book.pdf (this is a file not a directory)
└── spring
└── book.pdf (this is a file not a directory)
Problem 4: Brace expansion comes handy in other scenarios too. Here are some examples:
- Create a directory in your home directory called
lab6-q5
. From the root of the filesystem create 3 files in the lab6-q5 directory called:program.py
,people.csv
,data.xls
. - Change your current working directory to
/usr/share
. Create a directory in thelab6-q5
directory calledmovies
. Create 3 files in the~/lab6-q5/movies
directory calledmovies.lst
,marvel.txt
anddisney.doc
. - Remove the files:
program.py
,people.csv
,disney.doc
, andmarvel.txt
.
Take a screenshot of your terminal showing all the commands that you used to complete this question.
Challenge Question
Run this curl command:
curl https://cis106.com/assets/lab6cq.sh | bash
This will create a directory in your home directory called: challenge-Lab6
This directory has a bunch of files. Organize these file so that each file type has its own directory. Each file type must be moved to its respective directory. When you are done, the challenge-Lab6
directory should look like this:
challenge-lab6/
├── audio
│ ├── aac
│ │ └── all-aac-files-here
│ └── mp3
│ └── all-mp3-files-here
├── docs
│ ├── docx
│ │ └── all-docs-files-here
│ ├── pdf
│ │ └── all-pdf-files-here
│ └── xls
│ └── all-xls-files-here
└── images
├── jpg
│ └── all-jpg-files-here
└── png
└── all-png-files-here
Note: The directory tree you see here is just an example, you may or may not have the same files.
Tips
- Try to create your directory structure in a single command.
- Try working with multiple terminal windows open.
- List all the files in the directory sorted by file extensions to understand which directories you need to create.
Take a screenshot of your terminal showing all the commands that you used to complete this question.
What will you Submit:
- Place all the screenshots and answers to your questions in a the
lab6.md
file. - Convert your markdown file to pdf
- Push the changes to Github:
git pull; git add .; git commit -m "lab5 complete; git push"
- Submit the URL of
lab6.md
and the pdf file - Take a snapshot of your system and delete the previous snapshot.
Special Note
You are going to be using the git commands a lot. Here is a quick reference:
git clone repository/url/here
: is the command to clone a repository where cloning means downloading a repository to your computergit pull
: to pull/synchronize your repository from github to your local machine. Always run this command BEFORE you start working VS Codegit add .
: to track all the changes made to your file.git commit -m "label for your changes here"
: this command will label all the changes you added with theadd
commandgit push
: will send all your changes to your github repository
Always run the commands in this order:
pull
=>add
=>commit
=>push
Never use the github website to make changes to your repository unless you know what you are doing and can remember to pull the changes before working on your local repository!