Week 2 Discussion - Working with Unix#

Self-Help#

Exercise 37

What could the command man stand for (as an abbreviation)?

Exercise 38

Browse the manual page for the command man. man supports section numbers from 1 to 9. What could be motivation behind this?

Hint: try man 5 passwd and man passwd

Exercise 39

Why does man passwd show the manual for the command passwd but not for the configuration file /etc/passwd? Browse man man and find the section where this is explained.

Exercise 40

Which keys are very useful when browsing a man page?

Exercise 41

Why could the authors of the program apropos could have chosen this name?

Exercise 42

You have a directory 2021-Cambridge-travel with text and image files. The former have the file extensions txt and odt, and the latter jpg. You want to compress the directory using the tool tar and using the algorithm lzma.

Try the following approaches to achieve your goal. Which approach do you like most?

  • using man and apropos

  • using a search engine

  • curl cheat.sh/COMMAND_LINE_TOOL, e.g., curl cheat.sh/tar

Exercise 43

You look at the manual page for echo and see the following options:

… –help display this help and exit –version output version information and exit … Then you try the following command:

echo --version

which outputs --version instead of the version number of echo. What could be the reason?

Get Wild#

Exercise 44

  • What is ISO 8601?

  • What is its advantage?

Exercise 45

Find a command which generates today’s date in ISO 8601 format.

Optional challenge: Use only apropos and man as an exercise (instead of web search). apropos -s 1 only searches in section 1 (commands)

Exercise 46

  • What is a wildcard?

  • When would you use a wildcard?

Exercise 47

You have a folder with files that have the following format: date-name.filesuffix (date in ISO 8601 format). How would you list files which have the year 2010 to 2019 the month May in their name?

Configure#

Exercise 56

You have a file called diary.txt. Somehow the file seems to be corrupted. You suspect that your sibling could have played with your shell and edited the file to annoy you.

Do you have an idea how to find out what happened to diary.txt?

Exercise 57

At first sight Unix command line may seem very clunky and inefficient. For example navigating to directories using cd and cd .. may take more time compared to navigating in a file explorer.

Imagine that you have a file called projects/inf1/notes.md that you access very often. How could you access this file very efficiently using shell?

Differentiate#

Exercise 58

What is the difference between diff and sdiff?

Exercise 59

You have a 4GB sequencing data which you want to store in the cloud for the next five years. How can you ensure that the data is intact (not corrupted) when you download this data after five years?

Exercise 60

Find at least three checksum generation commands on your shell

Pipes#

Exercise 61

Write a sequence of at least three commands which are piped together

Make#

Exercise 62

  • What does a rule, dependency mean in context of make?

  • What happens with a rule when we invoke make?

Exercise 63

You have three files in your directory seq1.txt, seq2.txt, and seq3.txt which contain sequence of letters. You want to open these files using an ancient program which only supports reading capital letters.

  • write a makefile which create the capital letter versions of these files with the name seq*-capitalized.txt. You can use the tr command.

  • optional: Write a makefile which can capitalize any txt file and store it as *-capitalized.txt. Hint: use wildcards in makefile

Summary and reflection#

Exercise 64

Did you reach the following learning objectives for this week? Discuss with your partner.

  • Solve problems by consulting documentation

  • Use wildcards on the command line to work with multiple files and folders

  • Use grep, egrep, metacharacters, regular expressions, and find to search in file and directories

  • Customize Bash

  • Examine differences among files

  • Use pipes to deploy the output of one command as the input of another command

Last weeks review#

Exercise 65

Look at least ten problems from last weeks. A short review of last weeks will reinforce what you have already learned.