or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
2022 UC Carpentries Fall Workshop (The Unix Shell)
Workshop Details
Dates: September 6th - 13th, 2022
Time: 9am - 12pm
Workshop Agenda:
https://ucsdlib.github.io/2022-09-06-carpentries-uc/
Day 4: The Unix Shell
Software Installation:
Git for Windows - Windows
Windows: https://gitforwindows.org
Mac users will use the built-in Terminal application
required for Unix Shell and Git lesson
Recommended Text editors to use:
Nano
Notepad++ (optional text editor)
Lesson Data (download)
NOTES:
What is the shell?
Intro slides: https://docs.google.com/presentation/d/1JvAk7a-SgYUN4y8xXtQKB2Z2iwup0hEfJZmsZ-xlJ5Q/edit?usp=sharing
Navigating the filesystem
Webpage for help using the shell on windows machines: http://man.he.net/
Working with files and directories
Automating the tedious with loops
More about shell scripts: https://ryanstutorials.net/bash-scripting-tutorial/
Counting and mining with the shell
Regular Expressions resources:
LC regex cheatsheet: https://librarycarpentry.org/lc-data-intro/reference.html
regex101:https://regex101.com/
regexper: https://regexper.com/
Regex Testing: https://www.regextester.com/
Workshop Day 4
First name and Last Name/Organization/Dept./Email
Day 4 Exercises
Copying a file
Instead of moving a file, you might want to copy a file (make a duplicate), for instance to make a backup before modifying a file. Just like the mv command, the cp command takes two arguments: the old name and the new name. How would you make a copy of the file gulliver.txt called gulliver-backup.txt? Try it!
Renaming a directory
Renaming a directory works in the same way as renaming a file. Try using the mv command to rename the firstdir directory to backup.
Moving a file into a directory
If the last argument you give to the mv command is a directory, not a file, the file given in the first argument will be moved to that directory. Try using the mv command to move the file gulliver-backup.txt into the backup folder.
For loop exercise
Complete the blanks in the for loop below to print the name, first line, and last line of each text file in the current directory.
Count, sort and print (faded example)
To count the total lines in every tsv file, sort the results and then print the first line of the file we use the following:
wc -l *.tsv | sort -n | head -n 1
Now let’s change the scenario. We want to know the 10 files that contain the most words. Fill in the blanks below to count the words for each file, put them into order, and then make an output of the 10 files with the most words (Hint: The sort command sorts in ascending order by default).
__ -w *.tsv | sort __ | ______
Counting number of files
Let’s make a different pipeline. You want to find out how many files and directories there are in the current directory. Try to see if you can pipe the output from ls into wc to find the answer.
Counting the number of words
Check the manual for the wc command (either using man wc or wc –help) to see if you can find out what flag to use to print out the number of words (but not the number of lines and bytes). Try it with the .tsv files.
If you have time, you can also try to sort the results by piping it to sort. And/or explore the other flags of wc.
Case sensitive search in select files
Search for all case sensitive instances of a word you choose in the ‘America’ and ‘Africa’ .tsv files in this directory. Print your results to the shell.
Count words (case sensitive)
Count all case sensitive instances of a word you choose in the ‘America’ and ‘Africa’ .tsv files in this directory. Print your results to the shell.
Case insensitive search in select files (whole word)
Search for all case insensitive instances of that whole word in the ‘America’ and ‘Africa’ .tsv files in this directory. Print your results to a file results/hero-i.tsv.
Day 4 Reflection
Please enter how you will use the Unix Shell in your work or research here:
Day 4 Survey
Link to survey for today: https://forms.gle/5qgx8X6H3GRMacwD6
Day 4 Questions
Please enter any questions not answered during live session here:
1.
End Day 4