Bash Day 1 mid-day session

  1. Are there any questions on the materials you just watched?
  2. Let’s go together through the challenges, do some exercises, and debug problems.

Click on a triangle to expand a question:

Question 1 Relative vs. absolute paths. Using ~ as part of a longer path.
 
Question 2

If pwd displays /users/thing, what will ls ../backup display?

 
Question 3

Given the same directory structure, if pwd displays /users/backup, and -r tells ls to display things in reverse order, what command will display:

pnas-sub/  pnas-final/  original/
 
Question 4 What does the command cd do if you do not pass it a directory name?
 
Question 5 Starting from /Users/amanda/data/, which of the following commands could Amanda use to navigate to her home directory, which is /Users/amanda? Mark all correct answers.
 
Question 6 Suppose that you created a .txt file in your current directory to contain a list of the statistical tests you will need to do to analyze your data, and named it statstics.txt. After creating and saving this file, you realize you misspelled the filename! You want to correct the mistake, which of the following commands could you use to do so?
 
Question 7 Write simple aliases for safer mv, cp so that these do not automatically overwrite the target. Hint: use their manual pages. Where would you store these aliases? (no need to type any answer)
 
Question 8 Write simple alias for safer rm. (no need to type any answer)
 
Question 9

What is the output of the last ls command in the sequence shown below?

$ pwd
/home/jamie/data
$ ls
proteins.dat
$ mkdir recombine
$ mv proteins.dat recombine
$ cp recombine/proteins.dat ../proteins-saved.dat
$ ls
 
Question 10

Running ls -F in ~/Desktop/Shell/Users/nelle/sugars results in:

analyzed/  glucose.dat  mannose.dat  sucrose.dat  fructose.dat  maltose.dat  raw/

What code would you use to move all the .dat files into the analyzed sub-directory?

 
Question 11 In a directory we want to find the 3 files that have the least number of lines. Which command would work for this?
 
Question 12

In a directory the command ls returns:

fructose.dat  glucose.dat  sucrose.dat  maltose.txt

What would be the output of the following loop?

for datafile in *.dat
do
  cat $datafile >> sugar.dat
done
 
Question 13 Using diff to compare files and directories. (no need to type any answer)
 
Question 14

Discuss brace expansion. Try nested braces. Paste an example that works.

What will this command do:

touch 2022-May-{0{1..9},{10..30}}.md
 
Question 15 Use ps command to see how many processes you are running on the training cluster. Explore its flags. (no need to type any answer)
 
Question 16 Copy a file to/from the training cluster using either scp or sftp. (no need to type any answer)
 
Question 17 Bring up the manual page on rsync, then use it to synchronize a directory from the training cluster. (no need to type any answer)