In: Computer Science
Using repl.it, your own Linux installation, or other Linux emulator do the following and take screenshots for the steps that require it. Paste your screenshots into a word document, in the same order as the questions, and upload the file by 11 AM on Friday.
1. Show the contents of your home directory and take a screenshot
2. Create a directory named IT305 in your home directory and take a screenshot
3. Create a file called oldfile.txt in your home directory using the command line method of your choice. Make sure the file has at least 10 lines of characters in it. (I would suggest writing 10 lines that follow a pattern like this - This is line 1. This is line 2. and so on)
4. Create a new file in IT305 in the following manner:
use the nl command to number the lines of oldfile.txt, pipe that to the head command but only show the first 5 lines, pipe that to the tail command but only show 2 lines and redirect that output to the IT305 folder and create the newfile.txt. Do this on one command line. Take a screenshot of the command line that you use and of the contents of newfile.txt
5. Using the nslookup command, do a lookup of www.marymount.edu (Links to an external site.)and redirect the output to a file named marymount.txt
6. del the IT305 directory and take a screenshot that shows that it is no longer in your home directory
Here are the answers and screenshots from my Linux machine:
1) First switch to your home directory using cd ~ command. Then you can use ls or ls -l command to list its contents. ls -la will list even the hidden files.
2) Once in your home directory (use cd ~ command), you can create a directory using mkdir command. mkdir IT305 will create the required directory.
3) To create oldFile.txt, we've used here cat > oldFile.txt command. Once your enter this command, it allows you to type and enter file contents. After you finish, press Ctrl+D key combination to save the file and exit the cat command. File can be checked from ls command and its contents can be checked using cat command.
4) Here we're using piping to send the output of one command to another using pipe ( | ) character. I've shown the series of commands to show how it works. The complete command is highlighted in red box which is:
nl oldFile.txt | head -5 | tail -2 > IT305/newFile.txt
assuming you're in your home directory already (use cd ~) if not.
Content of newFile.txt created using this command is also shown at the end using cat.
5) To use nslookup, we need to specify either hostname or IP for it to resolve it IP or hostname respectively via DNS. Since we have to redirect its output to a file called marymount.txt, our command would be:
nslookup www.marymount.edu > marymount.txt
We can see that a new file marymount.txt has been created using ls and to check its contents use cat command as shown at the end. The file content will match the output of nslookup run earlier.
6) A directory can be deleted using rm command. Since IT305 directory isn't empty and contains newFile.txt created as part of answer 4, we've to use rm -rf to remove it. So command is rm -rf IT305 when executed inside your home directory. We can verify the same has been removed by issuing ls command as shown in the end.