Working with Unix
Working with Unix#
manto look up the flag for human-readable output from
Get help with
man maninto the console.
Wouldn’t it be nice if there was a calendar command? Use
aproposto look for such a command, then use
manto read about how that command works.
Solution to Exercise 5
-h. Human readable output output outputs the file size using MB, GB instead of bytes
Before I organized the photos by year, what command would have listed all of the photos of type
Before I organized the photos by year, what command would have deleted all of my hiking photos?
What series of commands would you use in order to put my figures for a data science course and the pictures I took in the lab into their own folders?
Solution to Exercise 6
mkdir data-science-course mkdir lab-pictures mv figure-*.svg data-science-course mv lab*.jpg lab-pictures
canada.txtfor lines that contain the word “New”.
Make five text files containing the names of states that don’t contain one of each of the five vowels.
Download the GitHub repository for this book and find out how many
.htmlfiles it contains.
Solution to Exercise 7
Download required files:
curl https://seankross.com/notes/states.txt -O curl https://seankross.com/notes/canada.txt -O
grep New states.txt canada.txt
grep -iv 'a' states.txt > states-without-a.txt grep -iv 'e' states.txt > states-without-e.txt grep -iv 'i' states.txt > states-without-i.txt grep -iv 'o' states.txt > states-without-o.txt grep -iv 'u' states.txt > states-without-u.txt
for vowel in a e i o u; do grep -iv $vowel states.txt > states-without-$vowel.txt; done
git clone https://github.com/seankross/the-unix-workbench find the-unix-workbench -iname '*.html' | wc -l
Use pipes to figure out how many US states contain the word “New.”
~/.bash_historyto try to figure out how many unique commands you’ve ever used. (You may need to look up how to use the
Solution to Exercise 8
grep New states.txt canada.txt | wc -l
uniqonly removes subsequent repeated lines. If the line is separated with a different line, then
uniqdoes not remove the duplicate.
The same behavior can also be achieved using
sort -uwithout using
sort ~/.histfile | uniq