Logbook will be kept on UMD T3 site from now on:
2/27/2019
Continued working on the networking issue. Our first idea (which was to use a bridged connection) is causing some problems. Bridged connections need to be used with an Ethernet connection, and it also hasn't been working unless we are connected directly to a router (which we aren't able to do here). Instead, we looked at using port forwarding. However, Hadoop would require a large number of ports to be forwarded if we continued with the installation, so we instead tried an alternate approach of installing multiple VMs on one computer, thereby bypassing the networking issues. We started to install a Namenode onto one of the VMs, following the tutorial at https://opensciencegrid.org/docs/data/install-hadoop/#installing-and-maintaining-hdfs. The Hadoop installation requires configuration for each node, which basically describes how the Hadoop network will manage files. Hadoop's files can be accessed by
cd /etc/hadoop
The config files are in /conf, but they are blank by default. Example files can be found in /conf.osg. We copied over the core-site.xml and hdfs-site.xml. There are some modifications to these files that need to be made, in particular the address of the Namenode, which can be set to its static IP address which we described previously. The next step is to configure GridFTP, and then try to validate the network by going to http://namenode.hostname:50070/dfshealth.jsp and verifying that the web interface works.
We will speak with Prof. Jabeen tomorrow to discuss our next steps. We are running into serious networking issues when trying to set up a cluster between our VMs, so we will work on finding a solution to that, as well as talking about next steps in terms of the new machine.Â
2/22/2019
We were going to meet with Prof. Jabeen today, but the meeting was cancelled again. We were going to start looking at the new machine, but that will be pushed to whenever we meet next week.
2/20/2019
We were supposed to meet with Prof. Jabeen today, but we canceled due to the snow.Â
2/15/2019
New IP - 10.0.2.1
Subet mask - 255.255.255.0
Gateway - 10.0.2.2
Domain IP - 10.0.2.0
See two enp0s3 interfaces, one which represents a gateway and one which represents a destination (flags U and UG, respectively).
route -n - lists network information
nmcli c - lists the available connections
nmcli d connect <network> - connects to the given network
Use Bridged Adaptor in VM settings, use the TAP thing because its for VMs. Could not connect to the internet with it, only NAT (adaptor settings) worked, but that's not what we're trying to do. Essentially, our bridged connection isn't working, I can't access the internet within my VM when it is adapted to a bridge connection. Current goal is to figure out how to properly set up a bridge connection (explain what a bridge connection is). Once we can access the internet through a bridge connection within the VMs, we can focus on creating a static IP address for each VM. After that, it should be easy to SSH into each other's VMs, and we can install Hadoop from there.
2/13/2019
After meeting with Prof. Jabeen again, we decided that our main goal at the moment will be creating a cluster of nodes on our VMs. One person will be the NameNode, and the other three will be DataNodes. Once we set up networking on our VMs, we should be able to SSH into each others' VMs and properly use Hadoop.
We mainly worked on connecting our VMs to the internet through a bridged connection. We noticed it wasn't working for any of us, which is because the bridged connection doesn't work over WiFi. We want to use a bridged connection because that is what works best for VMs - we didn't want to deal with creating a virtual network for the VM because it would make it harder to SSH into. We decided on using Ethernet cables to finish setting up the bridged connection. Once we set up the proper internet connections, we can create static IP addresses for each of our VMs, which will let us easily SSH into the VMs from our main computer.
2/9/2019
Started on installing Hadoop in our VMs, using this tutorial: https://opensciencegrid.org/docs/data/install-hadoop/. Ensured we had a supported operating system (we're using Scientific Linux, which is fine). Accessed root by running the "su" command and entering the root password, which was set during the VM setup. We installed the YUM, EPEL 7, and OSG repositories, which are necessary for the later Hadoop installation. Some of the tutorial was irrelevent (like the commands for updating previous versions of the repositories). To clean up the YUM repos, we ran the following commands:
root@host # yum clean all --enablerepo=*
and
root@host # yum updat
We focused on installing DataNodes, since we will be connecting to a primary NameNode (which will be part of the T3 cluster) eventually. Followed the commands for installation. The program files are found by doing "cd /etc" and then accessing the Hadoop files. We will be focusing on configuring our Hadoop installation after talking with Prof. Jabeen about what NameNode we are connecting to.
2/7/2019
I set up the VM in Virtual Box using the downloaded image. Used the operating system option of Linux with Red-Hat, since that is what Scientific Linux is based on..
2/5/2019
The group met with Dr. Jabeen, learned more about the WLCG system and what we'd be doing over the semester. Received instructions about the Hadoop (software which manages data) installation. Saw the physical Hadoop node which we may be able to add to the computing clusterÂ
Downloaded Scientific Linux 7 from the Scientific Linux page. We are using Scientific Linux because the OSG distribution of Hadoop only supports some operating systems, we are already familiar with Linux, and it is a much simpler OS compared to something like Red Hat.
HONR268N
November 27 2018
HW 10:
Ran the deep_dreams code in Google colab on a picture to create interesting effects.
DeepDream programs are deep learning systems or neural networks that is trained to find patterns in images and enhances those images on a target file. This specific deep_dream.py script, made by the Keras group, uses their inception_v3 neural net to preprocess the image. This network handles the pattern recognition of the source image, and layers different effects over the target image. The source image, or source image set in this case, was a number of different animals (most of them were dogs). This allows the neural net to overlay various animals, and specific features of those animals, onto the patterns of the image it is given.Â
Downloaded the code from: https://github.com/keras-team/keras/blob/master/examples/deep_dream.py
Put a test image into my Google Drive:
from google.colab import drive
drive.mount('/content/gdrive')
Ran this code to mount the Colab notebook, giving it access to drive files and operating space.
!cp /content/gdrive/My\ Drive/deep_dream.py deep_dreams.py
!cp /content/gdrive/My\ Drive/clouds.jpg clouds.jpg
Ran this code to copy the images and the python code to the Colab file inventory.Â
!python deep_dreams.py clouds.jpg /content/gdrive/My\ Drive/dreamimage-myimage
This command runs the Python script on the given banana.jpg file, placing the following image in the Google Drive:
November 20 2018
HW 9:
We can use the Colaboratory app in Google Drive to write Python code
Syntax, Variables, and Numbers:
Code:
pandas=10Â Â Â #Initializes a variable pandas and sets it to value 10
zebras=20
total_animals_in_zoo=pandas+zebras  #Initializes total_animals_in_zoo and sets it to the sum of pandas and zebras
print(total_animals_in_zoo) Â Â Â Â Â #Prints total_animals_in_zoo to the console
Output:
30
Code:
pi=3.14159 #Approx. #Initializes variables and assigns values diameter=10 area = pi * (diameter/2)**2 #Calculates area by multiplying pi by radius squared and assigns value to area variable print(area) #Prints the value of the variable
Output:
78.53975
Code:
#####Method 1######## a = [1, 2, 3] #Creates array a of length 3 and sets integer values b = ['cat', 'dog', 'fish'] #Creates array b of length 3 and sets String values a=b #Sets a equal to b b=a #Sets b equal to a (which is already equal to b) print('Method 1') #Prints out values of arrays print(a) print(b) #####Method 2######## a = [1, 2, 3] #Initializes arrays and assigns values b = ['cat', 'dog', 'fish'] temp = a #Assigns values of a to temp variable a = b b = temp #Fills b with temp values after assigning a print('Method 2') #Prints out values of arrays print(a) print(b)
Output:
Method 1 ['cat', 'dog', 'fish'] ['cat', 'dog', 'fish'] Method 2 ['cat', 'dog', 'fish'] [1, 2, 3]
The first method doesn't work because it sets b equal to the value of a immediately after setting a equal to the value of b. After the first line, both lists are equal to the value of b before, and the values of a were lost. The second
method stores this information in a temp variable, and retrieves it later, so the data switch works properly.
Code:
dog_legs=0Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Initializes variables and assigns values
human_legs=4
goldfish_legs=2
temp = dog_legs            #Uses two temp variables for swapping variables
temp2 = human_legs
human_legs = goldfish_legs
dog_legs = temp2
goldfish_legs = temp
              Â
print("Dog legs: %s") % (dog_legs) #Prints out values of arrays
print("Human legs: %s") % (human_legs)
print("Goldfish legs: %s") % (goldfish_legs)
Output:
Dog legs: 4 Human legs: 2 Goldfish legs: 0
Functions:
Code:
def round_to_two_places(num):Â Â Â Â Â Â Â Â #Creates function 'round_to_two_places(num)' which takes in one parameter
  return round(num, 2)            #Returns the parameter rounded to 2 decimal places using the 'round(x,y)' function
def round_to_n_places(num, places):Â Â Â Â Â #Creates function 'round_to_n_places(num, places)' which takes in two parameters
  return round(num, places)         #Returns the first parameter rounded to the second parameter decimal places
print("Number: %s") % (str(4.325456463)) Â Â #Prints the number
print("Two decimal places: %s") % (str(round_to_two_places(4.325456463)))Â Â Â Â #Prints the number rounded using the first function
print("Five decimal places: %s") % (str(round_to_n_places(4.325456463, 5)))Â Â Â #Prints the number rounded using the second function
Output:
Number: 4.325456463 Two decimal places: 4.33 Five decimal places: 4.32546
Built-in Functions:
Code:
a=[1,5435,324,3,645365,23,4,5665,435,31, -543] Â Â Â Â Â Â Â Â Â #Initializes variables and sets values
b=-10
c='cat'
print(c) Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Prints value of c
print(abs(b))                          #Absolute value                          Â
print(min(a))Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Min value
print(max(a))Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Max value
print(sum(a))Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Sum
print(len(c))Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Length of a string
print(sorted(a)) Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Sorts a list
Output:
cat 10 -543 645365 656743 3 [-543, 1, 3, 4, 23, 31, 324, 435, 5435, 5665, 645365]
This code performs various functions, including absolute value, min, max, and length, on different variables, and outputs the result.
Code:
def product_of_maxes(list1, list2):Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Creates function 'product_of_maxes(list1, list2)' which takes two parameters
  max1 = max(list1)                       #Calculates max of first and second parameters, and stores in variables
  max2 = max(list2)
  return max1*max2                        #Returns the product of the two maxes
a=[3243,645645,54346]Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Sets values to variables
b=[7,3,2]
print("A: %s\nB: %s\nProduct of maxes: %s") % (a, b, str(product_of_maxes(a,b)))Â Â Â Â Â Â #Outputs variables and the product of their maxes
Output:
A: [3243, 645645, 54346] B: [7, 3, 2] Product of maxes: 4519515
Booleans and Conditionals:
Code:
print(3==10) Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Prints the boolean value of the conditional (3==10), which is false
print(len('abc')==3) Â Â Â Â Â Â Â Â Â Â #Prints the boolean value of whether the length of 'abc' is 3, which is true
print(max([10,40,53]) < 25)Â Â Â Â Â Â Â #Prints the boolean value of whether the max value of 10,40,and 53 is greater than 25, which is true
print (5 != 3) Â Â Â Â Â Â Â Â Â Â Â Â Â #Prints the boolean value of whether 5 is not equal to 3, which is true
Output:
False True False True
This code uses boolean operators on various logical expressions
Code:
a = [0, 5, 10]
print (sum(a) - (min(a) + min(b)) > 0) Â #Prints boolean of whether the sum() of a minus the sum of the min() and max() of a is greater than 0
Output:
True
Code:
a=10 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Initializes variables and assigns values
b=20
if(a>b): Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Enters code block if a is greather than b
  print(a, 'is greater than', b)     #Prints values
elif(a<b): Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Enters code block if the above condition was not met and a is less than b
  print(b, 'is greater than', a)     #Prints values
else:Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Enters code block if none of the above conditions were met
  print("they're equal")         #Prints string
Output:
(20, 'is greater than', 10)
For the assigned values, the first if statement will be called, and "(20, 'is greater than', 10)" will be output. To reach the other outcomes, one case must have a less than b, and one must have a equal to b, which are shown below
Code:
a=20 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Initializes variables and assigns values
b=10
if(a>b): Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Enters code block if a is greather than b
  print(a, 'is greater than', b)     #Prints values
elif(a<b): Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Enters code block if the above condition was not met and a is less than b
  print(b, 'is greater than', a)     #Prints values
else:Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Enters code block if none of the above conditions were met
  print("they're equal")         #Prints string
Output:
(20, 'is greater than', 10)
Code:
a=10 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Initializes variables and assigns values
b=10
if(a>b): Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Enters code block if a is greather than b
  print(a, 'is greater than', b)     #Prints values
elif(a<b): Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Enters code block if the above condition was not met and a is less than b
  print(b, 'is greater than', a)     #Prints values
else:Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Enters code block if none of the above conditions were met
  print("they're equal")         #Prints string
Output:
they're equal
Code:
def longer_string(string1, string2): Â Â Â Â Â Â Â Â #Creates function 'longer_string' which takes in two parameters
  if(len(string1) > len(string2)):          #Runs if string1 is longer than string2
    return string1                  #Returns value of string1
  elif(len(string1) < len(string2)):         #Runs if string2 is longer than string1
    return string2                  #Returns value of string2
  else:                       #Runs if string1 and string2 are equal in length
    return                      #Exits function
print(longer_string('abc', 'jfkdla;s'))Â Â Â Â Â Â Â #Prints the longer string of the two using the 'longer_string(x,y)' function
print(longer_string('abcfdsafdasg', 'jfkdla;s'))
print(longer_string('abc', 'def'))
Output:
jfkdla;s abcfdsafdasg None
The code uses the len() function to compare the lengths of the two given strings. The method will output the longer string, and if both strings are equal in length, it will return "None".
Code:
def can_make_cake(eggs, flour, milk, almond_milk): Â Â Â Â Â Â Â Â Â #Creates function 'can_make_cake' which takes in 4 parameters
  #I can make cake if I have some kind of milk AND flour AND eggs
  return (milk or almond_milk) and flour and eggs > 0
print('Can I make cake?')Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Prints string
#What is the following line implying?Â
print(can_make_cake(10, True, False, True))Â Â Â Â Â Â Â Â Â Â Â Â Â #Implies that you can make cake since you have almond milk, flour, and more than 0 eggs
Output:
Can I make cake? True
The method call implies that you can make cake since you have almond milk, flour, and more than 0 eggs. Calling the method with an input of 0 eggs would look like the following:
print(can_make_cake(0, True, False, True))
which would output
False
Modulus Operator:
Code:
def abs_of_min_is_odd(list): Â Â Â Â Â Â Â Â Â Â Â #Creates function abs_of_min_is_odd(list) which takes in 1 parameter
  minimum = min(list)               #Calculates minimum of the list
  if (minimum % 2 == 0):              #Runs if the previously calculated minimum is even
    print("even")                 #Prints the string
  else:                      #Runs if the minimum is not even
    print("odd")                  #Prints the string
   Â
a = [-35423,-5432654,-352435,53252]Â Â Â Â Â Â Â Â #Initializes list and assigns values
print("A: %s") % (a) Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Prints value of list
abs_of_min_is_odd(a) Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Runs function abs_of_min_is_odd(x) on list a
Output:
A: [-35423, -5432654, -352435, 53252] even
Lists:
Code:
def select_third_element(my_list): Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Creates function 'select_third_element(my_list)' which takes in 1 parameter
  if(len(my_list) < 3):                         #Runs if the length of the list is less than 3
    return None                             #Returns None
  else:                                 #Runs if the length of the list is greater than or equal to 3
    return my_list[2] #remember index 0, so third element is index 2   #Returns element of list at index 2
foo = ['a', 'b', 'c', 'd'] Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Creates array and assigns values
print(select_third_element(foo)) Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Calls the function 'select_third_element(x)' on array
list1=[1,2,3]Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Creates arrays and assigns values
list2=[4,5,6]
list_of_lists=[list1,list2]Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Creates new list which contains previously created list
print(list_of_lists[1][2]) Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Prints out the value at index 2 of the list at index 1 of the new list
#Exercise:
print(list_of_lists[0])Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Prints the first list (which is at index 0 of the parent list)Â - [1, 2, 3]
print(list_of_lists[1])Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Prints the second list (which is at index 1 of the parent list) - [4, 5, 6]Â
print(list_of_lists[0][1])                        #Prints the value at index 1 of the first list          - 2
print(list_of_lists[0][2])                        #Prints the value at index 2 of the first list          - 3
print(list_of_lists[1][0])                        #Prints the value at index 0 of the second list         - 4
Output:
c 6 [1, 2, 3] [4, 5, 6] 2 3 4
Code:
real_madrid=['zidane', 'ramos', 'marcelo'] Â Â Â Â Â Â #Initializes arrays and assigns values
barcelona=['valverde', 'messi', 'pique']
teams = [real_madrid, barcelona] Â Â Â Â Â Â Â Â Â Â Â #Creates parent list which contains previously created lists
def losing_team_captain(team_list):Â Â Â Â Â Â Â Â Â Â #Creates function 'losing_team_captain(team_list)' which takes 1 parameter
  losing_captain = team_list[1][1]           #Stores the second value (captain) of the second list (losing team) in a variable
  print(losing_captain)                #Prints the value of the variable
 Â
losing_team_captain(teams) Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Calls the function
Output:
messi
Code:
standings=['mario', 'bowser', 'luigi','peach'] Â Â Â Â #Initializes array and assigns values
def purple_shell(racers):Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Creates function 'purple_shell(racers)' which takes 1 parameter
  temp = racers[0];                  #Assigns first value in list to a temp variable
  racers[0] = racers[len(racers)-1]          #Assigns value of last entry in list to first entry in list
  racers[len(racers)-1] = temp             #Assigns value of temp to last entry in the list
  print racers                     #Prints the list
 Â
purple_shell(standings)Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Calls the function
Output:
['peach', 'bowser', 'luigi', 'mario']
Loops:
Code:
def list_contains_seven(my_list):Â Â Â Â Â Â Â Â Â Â Â #Creates function 'list_contains_seven(my_list)' which takes 1 parameter
  for element in my_list:               #Traverses my_list with variable element
    if element ==7:                  #Returns True if value of element is 7
      return True                   #Returns False if reaches the end of the loop without running the if statement
  return False
print(list_contains_seven([6,14,5,7])) Â Â Â Â Â Â Â Â #Calls the function
print(list_contains_seven([6,14,5,9]))
def count_to_10(num):Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Creates function 'count_to_10(num)' which takes 1 parameter
  print
  while(num<10):                    #Runs while num is less than 10
    num=num+1                     #Increases value of num by 1
    print(num)                     #Prints the value of num
   Â
count_to_10(0) Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Calls the function
count_to_10(5)
count_to_10(11)Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Won't do anything since 11 is already greater than 10
Output:
True False 1 2 3 4 5 6 7 8 9 10 6 7 8 9 10
Code:
list=[1,21,7,-14,49,74,700]
def seven_counter(my_list):
  count = 0
  for element in my_list:
    if (element % 7 == 0):
      count+=1
  print count
 Â
seven_counter(list)
Output:
5
Dictionaries:
Code:
capitals={'United States': 'DC', 'France': 'Paris', 'Mexico': 'DF'}Â Â Â Â Â Â Â Â #Creates dictionary with String keys and String values, representing countries and capitals
populations={'UMD':40000, 'Towson': 30000, 'UMBC': 20000}Â Â Â Â Â Â Â Â Â Â Â Â Â #Creates dictionary with String keys and Integer values, representing colleges and populations
print(populations.get('UMD'))Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Prints the population of UMD by using the dictionary's .get() method on the given key
Output:
40000
Code:
############################DO NOT TOUCH THIS CODE#########################
deck={} Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #represents a deck of cards where the keys are the suits and values are lists of card values
hearts=[] Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Initializes empty lists for each suit
clubs=[]
diamonds=[]
spades=[]
values=['ace', 'two', 'three', 'four', 'five', 'six','seven', 'eight', 'nine', 'jack', 'king', 'queen'] Â Â Â #Initializes list of card values
def create_cards(suit): Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Creates function 'create_cards(suit)' which takes 1 parameter
  for value in values:                             #Traverses list values with String value
    suit.append(value)                             #Adds value of value to the given suit list
 Â
create_cards(hearts)Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Calls the function on each empty suit list
create_cards(clubs)
create_cards(diamonds)
create_cards(spades)
##################################Add your code here according to the comments ##########################################
#Use the strings 'h', 's', 'c', 'd' as keys, and add the lists of values to the dictionary.
deck={'h':hearts, 's':spades, 'c':clubs, 'd':diamonds}Â Â Â Â Â Â Â Â Â Â Â Â Â #Sets key values to each array of cards
#Print a view of dictionary (key, value) pairs
print deck.items()Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Uses the .items() method to print key value pairs
#Print a view of all of the keys
print deck.keys() Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Uses the .keys() method to print keys
#Print a view of all of the values
print deck.values() Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Uses the .values() method to print values
#Remove all of the spades from the deck
deck.pop('s') Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Uses the .pop() method to remove the 's' key value pair, which represents the spades
#Add a new entry to the dictionary with key 'j' and values 'joker1' and 'joker2'
jokers = ['joker1', 'joker2'] Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Creates a jokers array with the appropriate values
deck['j'] = jokers                               #Adds the array to the dictionary
#Clear the dictionary
deck.clear()Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Uses the .clear() method to clear the dictionary
Output:
[('h', ['ace', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'jack', 'king', 'queen']), ('s', ['ace', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'jack', 'king', 'queen']),
('c', ['ace', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'jack', 'king', 'queen']), ('d', ['ace', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'jack', 'king', 'queen'])] ['h', 's', 'c', 'd'] [['ace', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'jack', 'king', 'queen'], ['ace', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'jack', 'king', 'queen'],
['ace', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'jack', 'king', 'queen'], ['ace', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'jack', 'king', 'queen']]
External Libraries:
Code:
import math as m                         #I use the as m part so when I refer to the library I can just type m instead of math. Its just an abbreviation.
print(m.pi, m.log(32, 2)) Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Uses the .pi() and .log() functions of math to print pi and the log(2) of 32
#print(m.gcd(75348597,979531683))
print(m.cos(10))Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Uses the .cos() function to calculate the cosine of an angle in radians
#Here's a more advanced example.
import matplotlib                         #Imports libraries that will be usedÂ
import matplotlib.pyplot as plt
import numpy as np
# Data for plotting
t = np.arange(0.0, 2.0, 0.01) Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Creates function which goes from 0.0 to 2.0 with 0.01 space between each value
s = 1 + np.sin(2 * np.pi * t) Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Creates function with s = 1 + sin(2pi*t)
fig, ax = plt.subplots()Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Creates figure with one subplot
ax.plot(t, s) Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Plots t function on horizontal axis and s function on vertical axisÂ
ax.set(xlabel='time (s)', ylabel='voltage (mV)',         #Sets labels for horizontal/vertical axis and title
       title='About as simple as it gets, folks')
ax.grid() Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Constructs the previously created gridÂ
plt.show()Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Displays the figure
#What is the output?                       #It will output the graph of y = 1 + sin(2*pi*x) on a graph with the axes set from 0.0 to 2.0
data = {'a': np.arange(50),
        'c': np.random.randint(0, 50, 50),            #Returns a random number between 0 and 50 with a size of 50
        'd': np.random.randn(50)}                 #Returns a random number from the normal distribution centered on 50
data['b'] = data['a'] + 10 * np.random.randn(50)Â Â Â Â Â Â Â Â Â #Modifies previously generated random numbers and adds to the map
data['d'] = np.abs(data['d']) * 100 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Modifies previously generated random numbers and updates the map
plt.scatter('a', 'b', c='c', s='d', data=data)Â Â Â Â Â Â Â Â Â Â #Creates a scatter plot with the map values
plt.xlabel('entry a') Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Labels the horizontal and vertical axes
plt.ylabel('entry b')
plt.show()Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Displays the graph
Output:
(3.141592653589793, 5.0) -0.839071529076
This code will output the graph of y = 1 + sin(2*pi*x) on a graph from 0.0 to 2.0. The second graph is a scatter plot of random values ranging from 0 to 50.
Code:
import math as m                         #Imports libraries that will be usedÂ
import matplotlib                                               Â
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(0.0, 2.0, 0.01) Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Creates function which goes from 0.0 to 2.0 with 0.01 space between each value
s = np.tan(2 * np.pi * t) Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Creates function with s = tan(2*pi*t)
fig, ax = plt.subplots()Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Creates figure with one subplot
ax.plot(t, s) Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Plots t function on horizontal axis and s function on vertical axisÂ
ax.set(xlabel='x', ylabel='y',                  #Sets labels for horizontal/vertical axis and title
       title='Rohan\'s Graph')
ax.grid() Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Constructs the previously created gridÂ
plt.show()Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #Displays the figure
Output:
Python for CMS Analysis:
Code:
#imports some software packages we'll use
%matplotlib inline
import pandas as pd
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
inline_rc = dict(mpl.rcParams)
# a hashtag tells the program "don't read the rest of the line"
# That way we can write "comments" to humans trying to figure out what the code does
two_u = pd.read_csv('https://github.com/adamlamee/HEP-data/raw/master/Double_Muon_Run2011A.csv')
# two_e = pd.read_csv('https://github.com/adamlamee/HEP-data/raw/master/Double_Electron_Run2011A.csv')
# one_u = pd.read_csv('https://github.com/adamlamee/HEP-data/raw/master/Single_Muon_Run2011A.csv')
# one_e = pd.read_csv('https://github.com/adamlamee/HEP-data/raw/master/Single_Electron_Run2011A.csv')
data = two_u
# The .head(n) command displays the first n rows of a file.
data.head(3)
# The .shape command displays the (number of rows , number of columns) in a file.
data.shape
#Part One Let's get acquainted with this dimuon data set. Look at the cells above to find the answers to the following questions:
#In the table above, what do you think each of the column headings represent? How many events does this data set contain?
#The columns represent the trial, the event key. It also contains the type, energy, momentum vectors in the x, y, and z directions, the transverse momentum, eta, phi, and chargeÂ
#for each muon. The data set contains 475465 events.
# You can specify a column by dataset.columnName (e.g., two_u.E1)
# This makes a new column called "totalE" and fills it with (E1 + E2) for each event
data['totalE'] = data.E1 + data.E2
# This makes a new column called "Esquared" and fills it with E1^2 for each event
data['Esquared'] = data.E1**2
# makes the histogram
plt.hist(data.totalE, bins=10, range=[0,120], log=False)
plt.title("Dimuon Events")
plt.xlabel("x-axis label")
plt.ylabel("number of events")
Output:
Text(0,0.5,u'number of events')
The columns include the trial and event key. It also contains the type, energy, momentum vectors in the x, y, and z directions, the transverse momentum, eta, phi, and charge for each muon. The data set contains a total of 475465 events.
November 13 2018
HW 8:
wget http://hepcms-hn.umd.edu/~jabeen/Analysis/ (Links to an external site.)LHC-Higgs-Graviton.tgz - Downloads a file from a webpage
After downloading the LHC-HIGGS-GRAVITON.tgz file, unpacking it, and opening one of its root files, runningÂ
    HZZ4LeptonsAnalysisReduced->MakeClass("HiggsAnalysis")
created a class called "HiggsAnalysis", which provided a HiggsAnalysis.C and HiggsAnalysis.h file. These files contain the code that processes the decay of a Higgs to 2 Z bosons to 4 Leptons, which uses the TLorentzVector class.
HiggsAnalysis.C:
#define HiggsAnalysis_cxx
#include "HiggsAnalysis.h"
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>
void HiggsAnalysis::Loop()
{
  // In a ROOT session, you can do:
  // Root > .L HiggsAnalysis.C                           //Reads in the HiggsAnalysis.C file
  // Root > HiggsAnalysis t                             //Instantiates the HiggsAnalysis object
  // Root > t.GetEntry(12); // Fill t data members with entry number 12
  // Root > t.Show(); // Show values of entry 12
  // Root > t.Show(16); // Read and show values of entry 16
  // Root > t.Loop(); // Loop on all entries                    //Loops through the array of entries and outputs the data in the console
  // This is the loop skeleton where:
  // jentry is the global entry number in the chain
  // ientry is the entry number in the current Tree
  // Note that the argument to GetEntry must be:
  // jentry for TChain::GetEntry
  // ientry for TTree::GetEntry and TBranch::GetEntry
  //
  // To read only selected branches, Insert statements like:
  // METHOD1:
  // fChain->SetBranchStatus("*",0); // disable all branches
  // fChain->SetBranchStatus("branchname",1); // activate branchname
  // METHOD2: replace line
  // fChain->GetEntry(jentry); //read all branches
  //by b_branchname->GetEntry(ientry); //read only this branch
  if (fChain == 0) return;
  Long64_t nentries = fChain->GetEntriesFast();
  Long64_t nbytes = 0, nb = 0;
  TFile* output = TFile::Open("Dielectron_MC.root", "RECREATE"); // "RECREATE" would produce a new root file with name Dielectron_MC.root every time you run the code
  TH1F* Z_ee = new TH1F("Z_ee", "Di-electron candidate invariant mass", 200, 0, 200);
  TH1F* Z_ee2 = new TH1F("Z_ee2", "Di-electron candidate invariant mass 2", 200, 0, 200);    //Defines histograms for the second Z boson and the Higgs boson
  TH1F* H_zz = new TH1F("H_zz", "ZZ candidate invariant mass", 200, 0, 300);
  double el1mt = 0.0;
  double el1pt = 0.0;
  double el1eta = 0.0;
  for (Long64_t jentry=0; jentry<nentries;jentry++) {
    Long64_t ientry = LoadTree(jentry);
    if (ientry < 0) break;
    nb = fChain->GetEntry(jentry); nbytes += nb;
    // if (Cut(ientry) < 0) continue;
     TLorentzVector el1, el2, el3, el4;                         //Creates the TLorentzVectors for each lepton
     el1.SetPtEtaPhiM(f_lept1_pt, f_lept1_eta, f_lept1_phi, 0.0);
     el2.SetPtEtaPhiM(f_lept2_pt, f_lept2_eta, f_lept2_phi, 0.0);
     el3.SetPtEtaPhiM(f_lept3_pt, f_lept3_eta, f_lept3_phi, 0.0);            //Sets data for the leptons' TLorentzVectors
     el4.SetPtEtaPhiM(f_lept4_pt, f_lept4_eta, f_lept4_phi, 0.0);
     TLorentzVector zCandidate = el1 + el2;
     TLorentzVector zCandidate2= el3 + el4;                       //Calculates the TLorentzVector for the second Z boson by adding the TLorentzVectors of the third and fourth leptons
     TLorentzVector Higgs = zCandidate + zCandidate2;                  //Calculates the TLorentzVector for the Higgs by adding the TLorentzVectors of the Z bosons
     Z_ee->Fill(zCandidate.M());                                                           Â
     Z_ee2->Fill(zCandidate2.M());                            //Fills the histograms with the mass data of the Z bosons and Higgs boson
     H_zz->Fill(Higgs.M());
     el1mt = el1.Mt();
     cout << el1mt << endl;
    }
 Z_ee->Write();                                     //Outputs the histograms
 Z_ee2->Write();
 H_zz->Write();
 output->Close();
}
Z Boson 1:
Z Boson 2:
Higgs Boson:
The Z bosons had invariant masses of 80 and 29 GeV, and the Higgs boson had an invariant mass of about 121 GeV, according to the chosen root file's data.
November 12 2018
HW 7:
Madgraph:
tar -xvzf MG5_aMC_v2.6.0.tar.gz - Unzip a tar file
./bin/mg5_aMC - Start Madgraph
MG5_aMC>generate p p > t t~ - Create a new process (in this case, a proton-proton collision)
MG5_aMC>add process p p > W+ j, W+ > l+ vl - Add a new process (in this case, a decay chain)
MG5_aMC>output MY_FIRST_MG5_RUN - Create the output of these processes
MG5_aMC> launch MY_FIRST_MG5_RUN - Generate the events
python lhe2root.py MY_FIRST_MG5_RUN/Events/run_01/unweighted_events.lhe MY_FIRST_MG5_RUN.root - Convert the lhe file to a root file using the download lhe2root.py python script
October 25 2018
HW 6:
Arrays:
#include <iostream>
Â
using namespace std;
Â
int main() {
   Â
  int ii[3] = {1,2,3};  //creates an array of length 3 with values 1, 2,and 3
  int j=0;        //initializes j to 0
  while (j<3) {     //loops while j is less than 3
    cout <<" ii of "<<j<<" is "<<ii[j]<<endl;  //outputs the element in the array
    j++;        //increments j by 1
    }
   Â
  int LL[2][3] = {1,2,3,4,5,6};   //creates a 2D array with 2 rows and 3 cols
  j=0;              //sets j to 0
  int k;            //initializes k
  while (j<2) {        //loops while j is less than 2 (2 times)
    k=0;          //sets k to 0 for each loop
    while (k<3) {    //loops while k is less than 3 (3 times)
      cout<<" LL of "<<j<<" "<<k<<" is "<<LL[j][k]<<endl; //outputs element in array - will increment cols and then rows
      k++;      //increments k by 1                       Â
        }
    j++;       //increments j by 1
    }
  return 0;     //ends main method
}
Arrays are data structure that store variables of any kind at specified indices. Loops can be used to easily traverse arrays. 2-D arrays are arrays that store data
according to two indices (like a matrix).
Comments:
#include <iostream>
Â
using namespace std;
Â
/************************************************\
*Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â *
*          Arrays           *
*     This program demonstrates arrays    *
*Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â *
\************************************************/
int main() {
   Â
    // a loop to demonstrate 1D arrays
    int ii[3] = {1,2,3};
    int j=0;
    while (j<3) {
        cout <<" ii of "<<j<<" is "<<ii[j]<<endl;
        j++;
    }
   Â
    // a loop ot demonstrate 2D arrays
    int LL[2][3] = {1,2,3,4,5,6};
    j=0;
    int k;
    while (j<2) {
        k=0;  // do not forget to initialize k here
        while (k<3) {
            cout<<" LL of "<<j<<" "<<k<<" is "<<LL[j][k]<<endl;
            k++;
        }
        j++;
    }
    return 0;
}
Lines that are behind a "//" or between a "/*" and "*/" are comments that do not affect code
Reading Data:
#include <iostream>
#include <fstream> Â Â Â Â Â Â Â //allows for ofstream objects
Â
using namespace std;
Â
int main() {
  ofstream myfile;        //initializes myfile of type ofstream
  myfile.open("example.txt");  //accesses the given file within directory
  myfile<<"write some junk.";  //writes the given string to the fileÂ
  myfile.close();        //closes the file and flushes data
Â
  return 0;           //ends the main method
}
ofstream myfile : Creates an instance of ofstream, which is an output stream class.
myfile.open("file.txt") : Accesses the file and allows for editing.
Combining Code from Multiple Files:
/* MAIN.CPP */
#include <iostream>
#include <fstream>
// include the program dotprod.cpp so that we can find the dot_prod function, as well as scalarmult.cpp                                       Â
#include "dotprod.cpp"
#include "scalarmult.cpp"
using namespace std;
int main () {
  // declare the vectors                                                                                            Â
  double vector1[3];
  double vector2[3];
  double scalar;
  // open the input file                                                                                            Â
  ifstream infile;
  infile.open("vectors.txt");
  // store the input in the vectors and print the vectors for the user                                              Â
  infile>>vector1[0]>>vector1[1]>>vector1[2];
  cout<<" Vector 1 is ("<<vector1[0]<<","<<vector1[1]<<","<<vector1[2]<<")"<<endl;
  infile>>vector2[0]>>vector2[1]>>vector2[2];
  cout<<" Vector 2 is ("<<vector2[0]<<","<<vector2[1]<<","<<vector2[2]<<")"<<endl;
  infile>>scalar;
  cout<<" Scalar is " << scalar << endl;
  // close the input file                                                                                           Â
  infile.close();
  // call the dot_prod function from dotprod.cpp                                                                    Â
  dot_prod(vector1,vector2);
  // call the scaler_mult function from scalarmult.cpp
  scalar_mult(vector1, scalar);
  scalar_mult(vector2, scalar);
 Â
  return 0;
}
/* DOTPROD.CPP */
#include <iostream>
using namespace std;
double dot_prod(double v1[3],double v2[3]) {
  double dotdot;   //initializes double
  dotdot = v1[0]*v2[0]+v1[1]*v2[1]+v1[2]*v2[2];  //computes dot product of given arrays
  cout<<" The dot product is "<<dotdot<<endl;   //outputs dot product
  return 0;
}
/* SCALARMULT.CPP */
#include <iostream>
using namespace std;
double scalar_mult(double v1[3], double s) {
  //Calculates the scalar multiple
  double result[3];
  result[0] = v1[0] * s;
  result[1] = v1[1] * s;
  result[2] = v1[2] * s;
 Â
  //Outputs result
  cout << "The scalar multiple is ("<<result[0]<<","<<result[1]<<","<<result[2]<<")"<<endl;
}
Random:
#include <iostream>
#include <math.h>
using namespace std;
// this function is the actual random number generator
// this code is stolen from the book numerical recipes for fortran
// it relies on random generated from overflow of memory locations
// and is a pseudo random number generator
const int a = 7141; Â Â Â Â //initializes constants to modify the seedÂ
const int c = 54773;
const int mmod=256200;
//modifies seed so that a given seed returns a pseudo random number
double getFlatRandom(int& inew) {
double mranflat = 0.;
inew = inew%mmod;
double aa = double(inew)/double(mmod);
mranflat=aa;
inew = a*inew+c;
return mranflat;
}
// in this code, we will call the pseudo-random number generator and learn some things about its properties by filling and then displaying a histogram
int main() {
    int num;
    cout << "Enter the number of loop iterations: ";
    cin >> num;
    int inew = 2345; // This is the "seed" for the random number generator
    // we will put the results from the call into a histogram that we can look at, to learn some of its properties. This histogram has 10 bins.Â
    int histo[10] = {0,0,0,0,0,0,0,0,0,0};
Â
    double atmp;Â
   Â
    // call the random number generator 1000 times and fill a histogram
    for (int i = 0; i<num; i++){
         atmp=getFlatRandom(inew); // call the random number generator
cout << "Random number: " << atmp << endl;
histo[int(atmp*10)]++;Â // increment the histogram bin the number falls within
    }
    // print the histogram to the screen
    for (int i = 0; i<10; i++){
    cout<<i<<": ";
    for (int j=0; j<int((double(100*histo[i])/double(num))+0.5); j++) {
        cout << "=";
    }
    cout << endl;
        }
    return 0;
}
n = 10:
The random number generator works by overflowing an integer's memory location and using that as a seed in a prng algorithm. The same seed will return the same pseudo random numbers.
Increasing the number of iterations of the loop will increase the average spread of the pseudo random numbers, in the same way that flipping a coin more times will lead to an average heads/tails
value closer to 50%.
n = 100:
n = 1,000;
n = 10,000
October 4 2018
HW 5:
Conditional Statements:
if ( Condition ) { Body } : Runs the code in the Body section if the Condition is evaluated as true
Pointers:
&i : Returns the memory address of the variable i
int* p : Creates an integer pointer, which will point to a memory address
*p : Returns the data at the memory address pointed to by p
Program 1:
The code has two variables with completely separate memory addresses, so the data is totally different.
Program 2:
Since 'p' points to 'i's location in memory, they will return the same value whether i is directly changed or the value at 'i's memory address is changed.
Program 3:
This program creates an anonymous integer object, which doesn't have a variable associated with it. Because of this, the only way to access/modify the data is to use *p to directly access the memory address.
Practice:
This program creates two pointers. The first pointer was initialized to point at a double, and the second pointer was initialized to point to the same memory address as the first. This means that the values of *p1 and *p2 will always be the same, since they point to the same memory address.
September 27 2018
HW 4:
This program outputs "hello world".
ls /usr/include/c++/4.4.4 : Outputs the methods contained in the given header file
Variables : This code creates variables, assigns values to them, and outputs their values.
Operations : This code performs simple operations on a variable.
Non-Numeric Variables 1 : This code uses booleans in different operations
Loops : This code uses a loop to output a string of numbers
Loops 2 : In this code, I rewrote the given code using a for loop instead of a while loop.
September 20 2018
Making a shell script:
Create a .tsch file in emacs
#!/bin/tcsh : Color-codes the script to highlight variables, methods, and Strings
set ARG = $1 : Creates variable ARG and assigns first input to value (ARG refers to the variable, whereas $ARG refers to the variable's value)
^ This script searches for files that contain the given argument in the name and prints them out.
tcsh ./testscript.tcsh <argument> : Runs the script using the given arguments
chmod +x testscript.tcsh : Changes the permissions on the file
This script finds every file that contains the given argument in its name and outputs the results to a file.
This script replaces every instance cof "was" with "is" in the test.txt file.
September 13 2018
Linux Commands
echo $0 : Outputs your current shell (bash or tcsh)
echo $SHELL : Outputs the current directory within the shell
pwd : Outputs the current directory
ls : Outputs files within current directory
ls -l : Lists the current directory's files and their details in a long list format
ls --help : Describes the options for ls. -l outputs in long list format. -h outputs in human-readable format. Combining -l and -h outputs in long list human-readable format
mkdir new_directory : Makes a new directory with the given name in the current directory
cd new_directory : Enters the given directory
ls .. : Lists the files in the directory above the current directory
rmdir new_directory - Deletes the given empty directory
ls -CFx /usr/bin : Outputs a list of the files in the user's bin
ls -l /bin : Outputs a list of the files in the bin in long-list format
find /usr -name "*g++*" -print : Finds all of the files in the user's bin that contain the string "g++" in their name
which g++ : Outputs the path to the given executable (g++ in this case)
whoami : Outputs the current user
echo ~ : Outputs the home directory
ls ~ : Outputs the files in the home directory
cd ~ : Enters the home directory
touch file1 file2 test1 test2 : Creates text files with the given names
find . -name "test*" : Finds files in the current directory with the string "test*" in their name
rm file1 file2 test1 test2 : Deletes the given files
echo "test" : Outputs the given string or expression in the console
echo "test1" > log.txt : Creates a new text file (or overwrites an existing text file) with the given string
cat log.txt : Prints the contents of the given text file
echo "test3" >> log.txt : Adds the given string to the given text file without overwriting it
history : Prints previously entered commands
cp [path][source file][path] : Copies a file and places the copy in the given destination
mv [path][source file] [path] : Moves a file to the given destination
uname -a : Outputs system information as well as current time
whatis [command] : Gives a brief description of the command, similar to --help but simpler
cmp [file1] [file2] : Compares two files of the same type and outputs where they are different
sort [file] : Sorts a text file alphabetically by line
comm [file1] [file2] : Compares two text files and outputs lines unique to file1, lines unique to file2, and lines common to both
sed -i 's/[original string]/[new string]/g' [file] : Uses the stream editor to substitute a string in a text file with a new string
clear : Adds empty lines to the console until the window is blank
emacs -nw [file] : Opens the emacs editor for the given text file. CNTRL + X + S can be used to save, and CNTRL + X, CNTRL + C can be used to exit emacs.