Chapter 4: Working with Unix
4.1.2 Exercises
-
Use
manto look up the flag for human-readable output fromls.$ man lsAnd in the man page search:
/human-readable -
Get help with
manby typingman maninto the console.$ man man -
Wouldn’t it be nice if there was a calendar command? Use
aproposto look for such a command, then usemanto read about how that command works.$ apropos calendar $ man calendar
4.2.2 Exercises
-
Before I organized the photos by year, what command would have listed all of the photos of type
.png?$ ls *.png -
Before I organized the photos by year, what command would have deleted all of my hiking photos?
$ rm *hiking* -
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?
$ mv *datasci* data_science_course/ $ mv *lab* lab/
4.3.7 Exercises
-
Search
states.txtandcanada.txtfor lines that contain the word “New”.$ grep "New" states.txt canada.txt -
Make five text files containing the names of states that don’t contain one of each of the five vowels.
$ egrep -v "a" states.txt >> states_no_a.txt $ egrep -v "e" states.txt >> states_no_e.txt $ egrep -v "i" states.txt >> states_no_i.txt $ egrep -v "o" states.txt >> states_no_o.txt $ egrep -v "u" states.txt >> states_no_u.txt -
Download the GitHub repository for this book and find out how many
.htmlfiles it contains$ git clone https://github.com/seankross/the-unix-workbench $ cd the-unix-workbench $ find . -name "*.html" | wc -l
4.6.2 Exercises
-
Use pipes to figure out how many US states contain the word “New.”
$ grep "New\." states.txt | wc -l -
Examine your
~/.bash_historyto try to figure out how many unique commands you’ve ever used. (You may need to look up how to use theuniqandsortcommands).$ cat ~/.bash_history | sort | uniq | wc -l