Exercises

Practice your command-line skills with the following exercises.

Note: To download each file to your terminal, right-click on the file and select copy link address. Then, use the following command by replacing <Address> with the actual URL that you just copied to download the file.

wget <Address>

Submission Instructions

After completing the exercises, follow these steps:

  1. Write your answers in a text file.
  2. Send the text file to your instructor at skeshvadi@tru.ca .
  3. Expect feedback within a week after your submission to the same email address.

1. View the First 6 Lines

You have a large file (top-1m.csv) and want to see only the first 6 lines. Write a command to do this.


2. Extract the Second Column

You have a text file (top-1m.csv) with multiple columns separated by a comma, and you want to extract only the second column. Write a command to do this.


3. Copying a File to a New Directory

You want to copy a file (top-1m.csv) from the current directory to a new directory called backup. Which command(s) could you use?


4. Counting Lines, Words, and Characters

You have a text file (romeo_and_juliet.txt) and want to know how many lines, words, and characters it has. Write a command to do this.


5. Searching and Replacing with sed

You want to search a file (romeo_and_juliet.txt) for “Romeo” and replace it with Your Name. Write a command to do this (you need to use sed).


6. Shuffle and Save to a New File

You want to shuffle the lines of a file (top-1m.csv) and then save the first 10 lines to a new file called newfile.txt. Write a command to do this.


7. Sort a File Alphabetically

You want to sort a file (fruits.txt) in alphabetical order. Write a command to do this.


8. Counting Unique Lines

You want to count the number of unique lines in a file (fruits.txt). Write a command to do this.


9. View the Manual Page for curl

You want to see the manual page for the curl command. Write a command to do this.