Lab 1: Linux Commands (Basic)

 

1- If you are not familiar with Linux commands, please make sure you login (http://webminal.org/) and carefully study all 11 lessons. Alternatively, you can use your RPi.

2- Read the lecture slides.

3- This site offers a very good hands-on tutorial - you should create an account, login, click on play, then Terminal

4- In the lab Practice these basic Linux Commands start with Section 2

5- See other Online tools.

Part 1 - Practice ONLY

  1. What does –v option used for in mkdir –v command?  
  2. What does –vp option do in mkdir –vp?
  3. What is the purpose of ls –R?
  4. What does command stat used for?
  5. Let’s assume we want to create FOUR names followed by last names in a file called name.txt. How can we accomplish this using command lines only?
  6. What does du command used for? What does it stand for?
  7. Let’s assume we have a file located in ~/mydir11/mydir2/mydir3/name.txt. How can we use ln command to view this file using cat lastname from the home directory? Is it possible?  
  8.  Let’s say there is file that maintains a history of all the commands you have entered in the terminal and it is called .bash_history. How can you figure out where the file is located?
  9. How do you remove the content of directory without being prompted for confirmation?
  10. How can you figure out how much free memory is available on the disk?
  11. Clinton has been accused that her staff have recently deleted some emails. Assume all the emails in Outlook are saved on a giant file called user.dll, how is it possible to tell if the content of the file has been modified and who has done it?
  12. How can you tell which devices are mounted on your OS in Linux?
  13. Let’s say we have program running in the background. How can you kill the process? Explain all the steps.  
  14. How is it possible to find out if there was a power shut down on your computer over the past 24 hours?
  15. How can use view only the last 5 lines of a file called name.txt? 
  16. How can you find out the time a directory or file has been created?
  17. How can you find out if a user has accessed a file called name.txt?
  18. Let’s say we have a name.txt file consisting 1000 names, last names, and SSNs. Use a single Linux command to find the associated name and last name for a give SSN. 
  19. Let’s say we have a name.txt file consisting 1000 names, last names, and SSNs.
  20. What is the difference between find and whereis command in Linux?
  21. Assume a file called number.txt has the following content (below). Using a single command copy the second column into a file called number_col2.txt.
    1. 1, A, Z
    2. 2, B, Z
    3. 3, C, Z
  22. Let’s say we have two list of voters in the county. One is generated by Trump’s gang the other is generated by Clinton’s gang. Using a single Linux command, how can you tell if difference between the two files?
  23. Let’s assume we want to change the permission on a file to the following (below). How can we accomplish this using a single linux command?
  24. -rwx------. 1 farid farid 19,Aug 30 06: 31 number.txt

  25. How do you know what Linux version you have?
  26. Let’s say, upon Trump’s request Russian hackers remotely get access to Clinton’s server. They like to search for any string containing “ruin sanders” in all the files on her home directory. Using a single command to do this.  
  27. Let’s say we have a program called runme. How can you run this program on the background?
  28. What is the difference between commands touch and cat?
  29. How do you use echo command to display the following message: *** This is a test ****.
  30. What will be the purpose of running the following command: ls /etca/*release*
  31. What does SU command do?
  32. What does ping do? what command can you use to ping?
  33. What does ifconfig command do?
  34. Using the following command, utilize grep to display your gateway IP address: curl http://ipinfo.info/html/my_ip_address.php

Part 2 - Write Shell Scripts

Read about Shell Scripting and review the examples. Also lean about Vi Editor / Vi Commands.

 

A- In a file write a series of Linux commands that perform the following tasks (assume you are in your home directory):

  1. Create a directory called myprofile
  2. Create a subdirectory in myprofile called myemails
  3. Create a file called mytest.txt in myprofile directory.  
  4. Copy mytest.txt  into yourtest.txt   
  5. Copy mytest.txt  into ourtest.txt and place the new file in myemails directory
  6. Show the directory tree for myprofile directory
  7. Using for loop shell script command write 1-1000 in ourtest.txt file (you should have 1000 lines: 1,2,3,..) - learn about "for loop" in Shell Scripting.
  8. Display the last 10 values in ourtest.txt file

Submission for Part 2.A: Submit the Linux commands for each section.

B- In this part you are expected to write a Linux Shell Script to perform the following tasks:

  1. Display your IP address
  2. Display your MAC address
  3. Display your HOSTNAME
  4. Save the above information in a file called mynetwork.txt. Note that the created file must only have three lines in it.

Please note that each of the above information must be displayed on a separate line. Only the requested information should show up (nothiing else on the line should be displayed). HINT: Do NOT copy somehting from the web. You can use cut and grep commands. See example below. The script must be executable on the machines in the lab. How do you execute the shell script?

 

Submission for Part 2.B: Submit your working script and the output of your scrips for Part 2. You must show that your script works. You can use Salazar 2006. You must demonstrate before the end of the class; please come early.

 

 

Here is an example of a shell script that helps you find your IP ADDRESS (and some other stuff):

 

#!/bin/bash
# Author: Farid Farahmand 
# Aug. 30, 2016 - Version 1
#----------------------------
# Do not copy and paste!
# bash clear screen command
clear;
# Let's just print 1-10 for fun
for a in `seq 1 10`; do
echo "$a"
done # Find the Ip address
ifconfig | grep broadcast > temp1.txt
cut -f2 -d' ' temp1.txt # use the same technique to find the MAC address # remove temp files rm temp*.txt

 

 

Part 3 - Practice Linux Commands & Utilities

Once again, review the following:

Submit the answer to all the quesitons below.

  1. Let’s say we have program running in the background. How can you kill the process? Explain all the steps.  
  2. How is it possible to find out if there was a power shut down on your computer over the past 24 hours?
  3. How can view only the last 5 lines of a file called name.txt? 
  4. How can you find out the time a directory or file has been created?
  5. How can you find out if a user has accessed a file called name.txt?
  6. Let’s say we have a name.txt file consisting 1000 names, last names, and SSNs. Use a single Linux command to find the associated name and last name for a give SSN. What is the command?
  7. What is the difference between find and whereis commands in Linux?
  8. Assume a file called number.txt has the following content (below). Using a single command copy the second column into a file called number_col2.txt. Write the command.
    1. 1, A, Z
    2. 2, B, Z
    3. 3, C, Z
  9. Let’s assume we want to change the permission on a file to the following (below). How can we accomplish this using a single linux command?
  10. -rwx------. 1 myfile 19,Aug 30 06: 31 number.txt

  11. How do you know what Linux version you have?
  12. Let’s say we have a program called runme. How can you run this program on the background?
  13. How do you use echo command to display the following message: *** This is a test ****.
  14. What does su command do?
  15. Run ifconfig command on your computer. How many NIC cards do you have? What are they called?
  16. From your terminal run the following command and answer the questions below: curl https://ipinfo.info/html/my_ip_address.php
  1. Linux command netstat displays information on the network configuration and activity of a Linux system, including network connections, routing tables, interface statistics, and multicast memberships. The following exercise explores how to use the netstat command to extract different types of information about the network configuration of a host. Try these commands:

For Practice only - Optional

Open a terminal. Type sudo tcpdump –i ethx -n. Ethx is the NIC you are connected to. In a different terminal ping your computer such that the packet size is 100 bytes and packet content (or pattern) is set to all FF (ping -c 5 -s 100 -p FF IP_ADDRESS ). When the pinging is completed you can press Cntl C to stop tcpdump. Answer the following question

  • What is the purpose of tcpdump command? You can do a man on the command to learn more.
  • What is the –n option for in the tcpdump command?
  • How can you redirect the results of tcpdump into a file called tcpdump_result.txt? What is the command? Open tcpdump_result.txt and check its content.
  • From the command line, using grep command how can you verify how many icmp packets where sent? What is the command you will be using?
  •