Wrapping it All Up (All Review Questions) - Green-Biome-Institute/AWS GitHub Wiki
Back to Section 8: Basics of Bash Scripting
Conclusion
You've finished the Command Line Training Module for Scientists! Nice work! Let's see if you can answer all of the review questions without going back to the wiki pages related to them... This time the questions don't have the answers immediately underneath. They are at the bottom of this page, so refrain from scrolling down to test yourself. Copy and paste the questions into a text document (like word) and try answering them!
Questions
-
How does the CLI compare to the graphical user interface of your computer?
-
Why is the CLI a practical and important skill?
-
How can the command line make your experiments more efficient?
-
How do you review past commands?
-
When you log onto an EC2 instance within your CLI window, do your commands get sent to your own computer or a virtual computer in the AWS cloud?
-
What is the command line prompt?
-
Can you access the internet via the command line?
-
What is your current working directory?
-
How do you find out what your current working directory?
-
How do you list the contents of your directory?
-
How do you change directories to a subdirectory named "example-dir"?
-
How do you move back to your home directory?
-
What are directories?
-
What is a subdirectory vs a parent directory?
-
What are text and data files used for?
-
What is an executable?
-
How can you find out more information about a given command?
-
What is a command option?
-
What command can you use to gain administrator privileges on the CLI session?
-
What is a variable?
-
What is the path of a directory?
-
What command is useful for when we are a bit lost and don't know where we are on the computer?
-
What command do you use to create a new directory?
-
What command do you use to create empty text or data files?
-
How do you move files to different locations?
-
How can you get the path of a location that you want to move a file into?
-
How do you edit files?
-
How do you read files into the CLI window?
-
How do you copy files?
-
How do you delete files?
-
What command displays the amount of free storage space in our EC2 instance?
-
What is a block device similar with your own computer to in the context of an EC2 instance?
-
What command lists the block devices?
-
What command shows us a real-time view of the softwares that our EC2 instance is currently running?
-
What command shows us the number of newlines, words, and bytes in a specific file (or multiple files!)?
-
What command searches for patterns within files or directories?
-
What command takes the output of one command and allows you to use it as the input of a second command?
-
What command can search for and change a pattern inside of a file?
-
What are commands that you can use for downloading software packages?
-
Which commands download files from web servers?
-
What command would you use to uncompress a
.tar
or.tar.gz
file? -
What command would you use to uncompress a
.gz
file? -
What command would you use to uncompress a
.zip
file? -
What commands can you use to download python packages?
-
How do you download a Github repository to your current working directory?
-
Which character is symbolic of "all files" (for instance, "list all files in the current directory", or "list all files that end with ".txt")?
-
Which character redirects the the output of a command into a new file and overwrites any other file that might already exist with the name you gave it?
-
Which character redirects the the output of a command into a new file and but, instead of overwriting another file, appends that output to the end of the file instead?
-
Which command allows for you to create a secure connection to another computer host (like an EC2 instance)?
-
What is a private keypair used for?
-
Which command would you use to copy a file from your computer to another computer?
-
What information besides the keypair is required to log into another computer system with SSH? What extra information do you need for using SCP?
-
What happens when you use the command
(Control + C)
when a program is running? -
What command would you use to create a virtual terminal for running programs on behind the scenes on your EC2 instance?
-
What do you press to log out of a
tmux
virtual terminal? -
Which
tmux
options do you use to reattach to a virtual terminal? -
What are 2 tools you can use for finding software that is relevant to doing analysis that you are interested in?
-
Where should you look to find out how to download and install a third party software?
-
Where can you find out more information about how to use the software? What command or option is useful for doing this?
-
What information should you include when you ask a question on an online forum (or any time you ask a question for that matter!)?
-
What is Bash?
-
What is a bash script?
-
What is a variable?
-
What is a
for
loop? -
If you try to operate a script and it tells you you don't have the correct permissions, what command can you use to change the permissions of the file so that you can execute it?
-
Is scripting / programming something that you are capable of learning?
Of course!! All it takes is practice. (I thought I'd just give you the answer to this one)
Answers
-
You can do many of the same things on the command line as you can with your mouse. You can open and navigate around folders, create and edit files, and use programs.
-
It is an important skill for many fields of science that require analyzing large datasets, for have a larger set of tools to analyze data with because many programs don't have GUIs, and for furthering your career as a scientist.
-
You can set up multiple data analyses to run one after another to change variables in between runs, meaning that you don't have to manually do that yourself and free up your own time.
-
You press the up arrow.
-
They get sent to a computer in the cloud! Your personal computer will not receive any of the commands you send it!
-
It is the area for you to enter text and commands that will be sent to the computer. The prompt contains text that holds information regarding the user who is logged into the computer, the name of the computer (the host), the current working directory (where you are on the computer, and the type of user you are.
-
Yes!
-
It is the location on your computer that your CLI session currently resides and decides what files and directories you have immediate access to.
-
You use the command
pwd
. -
You use the command
ls
. -
You use the command
cd
with the folder named after it:cd example-dir
. -
You use the command
cd
orcd ~
-
They are like folder and they store other files or more directories.
-
A subdirectory is inside of a parent directory.
-
Text and data files hold information! They can have a variety of different filetypes, like excel files (.xls), comma-separated values (.csv), or the text-based format for storing both a biological sequence and its corresponding quality scores (.fastq), etc.
-
An executable is a file whose contents holds instructions for the computer to follow. Can be thought of as a "program".
-
Use the manual! To read the manual, use the command
man [command-name]
, example forls
:man ls
. You can also sometimes use the option--help
after the command, ex:[command] --help
-
A command option is a feature for customizing a command. Sometimes commands can be run in different ways (like using ls to list in different ways) or the options are used to input datafiles.
-
The command
sudo
is used for gaining administrator privileges, but is dangerous to use because you can potentially overwrite important files! -
A variable is a storage container for information.
-
A directories path is the series of directories that lead the computer to that directory. For example, in
dir1/dir2/dir3/dir4/file.txt.
, the path to the filefile.txt
isdir1/dir2/dir3/dir4/
. -
The command
pwd
is useful for finding out what our current working directory is. -
You can use the
mkdir [directory-name]
command to build new directories. -
You can use the
touch [filename]
command to create empty text or data files -
You use the
mv
command to move files or directories to different locations. -
You can either use
/..
to signify that you want to move the file into the parent directory, or you can navigate into the directory you want to move the file into and usepwd
to find its path. Then you put a ~ at the beginning of the path because that will tell the computer that it should look for that path within the home directory. -
To edit files you can open them in the Nano editor by using the command
nano [filename]
. -
You use the command
cat [filename]
to read a file. -
You use the command
cp [filename1] [filename2]
copyfilename1
into a new file with the namefilename2
. -
You use the command
rm [filename]
to delete files -
df -h
! -
It is like an external hard drive, that when mounted (attached) onto the computer, adds storage space that you can save files to.
-
lsblk
-
top
-
wc
-
grep
-
The pipe command
|
. -
sed
-
apt
,yum
,dpkg
. For usingapt
the syntax is:sudo apt install [package-name]
-
wget
andcurl
-
tar
-
gunzip
-
unzip
-
pip
andconda
(but you can only useconda
if the program Anaconda is installed, for our EC2 instances, you can useconda
instead ofpip
!) -
git clone [desired-repository-url]
-
*
-
>
-
>>
-
To use the Secure Shell Protocol, SSH, you use the command
ssh
. -
It acts like a password and is necessary to get permission to use SSH to log into another computer.
-
To use the Secure Copy Protocol, SCP, you use the command
scp
. -
You need to have the username you will log into the other computer system with and the hostname of the computer. For SCP, you also need to have the path to the location you want to copy your file to or the path and the filename that you want to copy to your own computer.
-
It force quits the program and send you back to the command prompt!
-
tmux
orscreen
-
You press and release
(Command + B)
together and then pressD
-
attach-session
to tell tmux you want to attach to a currently running virtual terminal and-t [virtual-terminal-name
to tell tmux the name of that virtual termianl you want to attach to. -
Both a literature search and Google are good options for finding the names and use cases of analysis softwares.
-
Look at the documentation pages for the software. This is usually in the Github repository or on the university / academic lab's website.
-
Look at the documentation, README, or manual pages (these are all effectively synonymous). Use the command
man [software-package]
or the--help
option after you have installed the software. -
Be sure to include: The question you are asking in as clear terms as you can word it, How you have already tried to answer the question, meaning other questions you have asked, webpages or sources you have looked at, and attempts at solving the problem you have already tried.
-
Bash is the program that receives the commands you enter in the Command Line Interface window, looks for the instructions to operate those commands on the computer, and then executes those instructions.
-
A bash script is a collection of instructions that Bash follows one after another. This is done to automate tasks instead of having to manually enter them yourself.
-
A variable is a container used to temporarily store information. It can change when it is assigned another value (numbers or text).
-
A
for
loop is a set of instructions for the computer to follow until a condition is met. When the computer enters a for loop, it is given conditions (like "until the variablei
is equal to 100, withi
starting at 0, andi
increasing by 1 every loop) that tell it when (if ever) to leave thefor
loop. For as long as it is inside of the for loop, it follow the instructions inside of it. -
chmod +x [filename]