Homework #1

Homework #1#

Completing this assignment

For this assignment, create a single text file in nano called homework1.txt and provide the sequence of commands needed for each problem.

You will then upload homework1.txt to Brightspace.

Important

All work must be your own.

You may not use generative AI / large-language models for any part of this assignment.

  1. Starting in your home directory:

    • Create the directory structure:

      ~/homework/1/files/
      
      solution

      Starting in your home directory:

      mkdir homework
      cd homework
      mkdir 1
      cd 1
      mkdir files
      

      or

      mkdir homework
      mkdir homework/1
      mkdir homework/1/files
      

      or if you looked at man mkdir

      mkdir -p homework/1/files
      
    • Now move into the files/ sub-directory you created, and create a file called problem.txt using the touch command.

      solution
      cd ~/homework/1/files
      touch problem.txt
      
  2. For this problem we will use the same directory-structure/files from the shell lessons (see Some Sample Data to remember how to get this).

    • Change to the directory:

      ~/shell-lesson-data/exercise-data/alkanes
      
      solution
      cd ~/shell-lesson-data/exercise-data/alkanes
      
    • Now make a subdirectory under that called tests/ and change directory into tests/.

      solution
      mkdir tests
      cd tests
      
    • From within tests/ copy the files cubane.pdb, ethane.pdb, and octane.pdb from the directory above into your current directory. You should use a single command for it.

      solution
      cp ../cubane.pdb ../ethane.pdb ../octane.pdb .
      
  3. Let’s consider two ways to do the same task—moving a file to a new location. We want to move a file ~/answer.txt to ~/homeworks/answer.txt

    • Method 1: copy + delete

      • In your home directory, create a file called answer.txt using touch

      • Create a directory called homeworks/

      • Copy the file answer.txt into homeworks/

      • Delete the version of answer.txt in your home-directory (only the version homeworks/answer.txt) should remain.

      solution
      touch answer.txt
      mkdir homeworks
      cp answer.txt homeworks/
      rm answer.txt
      
    • Method 2: moving

      • Back in your home directory, create a file named answer2.txt (again using touch).

      • Move this file, using a single command, into the homeworks/ directory you created previously.

      solution
      touch answer2.txt
      mv answer2.txt homeworks
      
  4. Using man ls, find the option/flag that sorts files by size (largest file first). In addition to this new option, also use the -l option to get a long listing.

    • Give the ls command that will do this sorting + long listing

      solution
      ls -lS
      

      or

      ls -l -s
      

      or

      ls -l --size
      
    • In ~/shell-lesson-data/exercise-data/alkanes/, show the (long-listing) output when you sort by size

      solution
      -rw-rw----. 1 zingale zingale 1828 Apr 23  2025 octane.pdb
      -rw-rw----. 1 zingale zingale 1226 Apr 23  2025 pentane.pdb
      -rw-rw----. 1 zingale zingale 1158 Apr 23  2025 cubane.pdb
      -rw-rw----. 1 zingale zingale  825 Apr 23  2025 propane.pdb
      -rw-rw----. 1 zingale zingale  622 Apr 23  2025 ethane.pdb
      -rw-rw----. 1 zingale zingale  422 Apr 23  2025 methane.pdb