Lab 6 - 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/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/q1
directory. - Create a directory called
log-files
inside thelab6
directory. Move all the log files to thelog-files
directory. - Long list all the configuration files in the
lab6/q1
directory. sorted by file size. Modify the ls command with the proper options so that the output looks like this: (Notice the date). Then create the directorylab6/config-files
and move all the config files inlab6/q1
.-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 ? and [] wildcard
- Create the directory:
hidden-files
inside thelab6
directory. - List only the hidden files inside
lab6/q2
directory then copy them to thehidden-files
directory. - List all the files with a 2 letter file extension in the
lab6/q2
directory then remove them. - List and then remove all the files with a 4 letter file extension in the
lab6/q2
directory that start with letterT
and end with letterx
- List all the files, inside the
lab6/q2
directory, that start with letterl
(lowercase L) or letterr
, have one vowel after letterl
or letterr
, and and a number before the file extension. - Create a directory called
random
inside thelab6
directory. - Use the wildcard in step 5 to move the files to the
random
directory
Take a screenshot of your terminal showing all the commands that you used to complete this question.
Question 3 | 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
├── 2024
│ └── book.pdf (this is a file not a directory)
└── 2025
└── book.pdf (this is a file not a directory)
Problem 4: Brace expansion comes handy in other scenarios too. Here are some examples:
- From the root of the filesystem, create 3 files in the
~/lab6/q3
directory called:program.py
,people.csv
,data.xls
. - From the root of the filesystem, remove the files:
_file0.old
_file1.old
,_file2.old
located in~/lab6/q3
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/lab6/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:
Note: The directory tree you see here is just an example, you may or may not have the same files.
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.
Here is what you are not allowed to do:
- Create a directory for every file type. It defeats the purpose of the question. There are a lot of file types but you should be able to logically categorize them.
- Move the files 1 by 1. It defeats the purpose of learning how to use wildcards.
- Create the directories 1 by 1. It defeats the purpose of learning brace expansions.
Tips
- List the directory sorted by file extension.
- Write down all the different file types and come up with a categorization
- There should be a directory for every category.
- Create the directory tree using brace expansion. By this point you should know how many and which directories you will need. There should not be a single directory with only 1 file.
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!