Bash Day 1 mid-day session
- Are there any questions on the materials you just watched?
- 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 commandcd
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 itstatstics.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 safermv
, 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 saferrm
. (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
Usingdiff
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
Useps
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 eitherscp
or sftp
. (no need to type any answer)
Question 17
Bring up the manual page onrsync
, then use it to synchronize a directory from the training cluster. (no need to type
any answer)