Unix Exercises: Difference between revisions

From 22126
Jump to navigation Jump to search
(Created page with "__NOTOC__ {| width=500 style="font-size: 10px; float:right; margin-left: 10px; margin-top: -56px;" |Previous: None |Next: Python Recap and Objects |} You did complete the Course preparation, right? Otherwise, all of this will fail. == Required course material for the lesson == PowerPoint: [https://teaching.healthtech.dtu.dk/material/22113/22113_01-Unix.ppt Introduction to Unix] The videos are not entirely in sync with the updated PowerPoint. Video: [https:...")
 
No edit summary
Line 11: Line 11:
The videos are not entirely in sync with the updated PowerPoint.   
The videos are not entirely in sync with the updated PowerPoint.   


Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=110b2544-db60-4491-95cd-af270127f161 Unix intro and navigation] Monday
* Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=110b2544-db60-4491-95cd-af270127f161 Unix intro and navigation] Monday
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=88cb52db-1c77-4a98-94db-af270127d0dc Copying, Moving, Renaming files. Changing permissions] Monday
* Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=88cb52db-1c77-4a98-94db-af270127d0dc Copying, Moving, Renaming files. Changing permissions] Monday
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=fa98c15f-5c50-4ea3-8c85-af270127aedf Using shortcuts in Unix making it easier] Monday
* Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=fa98c15f-5c50-4ea3-8c85-af270127aedf Using shortcuts in Unix - making it easier] Monday
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=7f775d1b-2788-45ee-b4ac-af2701279221 File inspection and editors in Unix] Monday
* Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=7f775d1b-2788-45ee-b4ac-af2701279221 File inspection and editor in Unix] Monday
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=16f1e9bd-8044-4a97-b033-af27012771e2 Manipulating files: wc, paste, cut & sort] Monday
* Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=16f1e9bd-8044-4a97-b033-af27012771e2 Manipulating files: wc, paste, cut & sort] Monday
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=5ecff806-b2de-42f7-ab97-af2701274f66 Manipulating files: grep and pipelines] Monday
* Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=5ecff806-b2de-42f7-ab97-af2701274f66 Manipulating files: grep and pipelines] Monday
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=0679c534-a422-4ed6-9f52-af27012730b2 Touching upon various relevant subjects] Monday
* Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=0679c534-a422-4ed6-9f52-af27012730b2 Touching upon various relevant subjects] Monday
 


Resource: [https://teaching.healthtech.dtu.dk/unix The UNIX resource used across Health Tech courses]   
Resource: [https://teaching.healthtech.dtu.dk/unix The UNIX resource used across Health Tech courses]   

Revision as of 15:44, 19 November 2025

Previous: None Next: Python Recap and Objects

You did complete the Course preparation, right? Otherwise, all of this will fail.

Required course material for the lesson

PowerPoint: Introduction to Unix The videos are not entirely in sync with the updated PowerPoint.


Resource: The UNIX resource used across Health Tech courses Resource: Biological knowledge needed in the course Resource: UNIX Tutorial for Beginners Resource: UNIX/LINUX Tutorial

Subjects covered

  • Basic file handling in UNIX
  • Understanding and navigating the file system
  • Many different Unix commands
  • Scripting in bash

Exercises to be handed in

Use a text editor to create a file mycommands.txt where you write all commands and observations from the exercises below. Use copy/paste to insert the commands you ran.

Notes:

  • Make sure it is clear which exercise you are solving.
  • Work from your home directory unless you explicitly state otherwise.
  • Data files are available in the collection of files.

Exercises to do after Monday

It is assumed that you have downloaded the three files: ex1.dat, ex1.acc and orphans.sp before starting.

  1. List the files in the current directory.
  2. Copy ex1.acc to myfile.acc.
  3. View the contents of both files to ensure they are identical.
  4. Copy ex1.dat to myfile.acc (overwriting it).
  5. Check that the contents of myfile.acc have changed.
  6. Delete myfile.acc.
  7. Create a directory called test and move the three files into it.
  8. Create a directory data and move the three files into data instead.
  9. Remove the now-empty test directory.
  10. Change directory to data and confirm that the three files are there. Return to your home/work directory afterwards.
  11. Create three new directories, each inside the previous one, like Russian dolls: newtest/one/two.
  12. Move the data directory into the innermost two directory.
  13. Confirm that the three files moved along with the data directory.
  14. Copy the three files from data back into your home directory.
  15. Remove all newtest directories and data with a single command.
 Warning: Make sure you are in the correct parent directory before running a recursive remove.
  1. Count the lines in ex1.acc and ex1.dat.
  2. Concatenate ex1.acc and ex1.dat into ex1.tot. Ensure gene IDs appear first and numerical data after.
  3. Merge/paste ex1.acc and ex1.dat together into ex1.tot, overwriting the previous file. Verify corresponding lines appear together.
  4. Extract (cut) SwissProt ID and the 3rd numerical field (columns 1 and 5) from ex1.tot and save into ex1.res.
  5. Find the three SwissProt IDs in ex1.res with the largest numbers in column 2. Display only the IDs.
  6. Find the lines in orphans.sp that contain a GenBank accession number using grep. There are 85; verify this.
  7. How many human genes with SwissProt IDs exist in orphans.sp? How many are hypothetical? (11)
  8. How many rat genes exist, and how many of those are precursors? (9)
  9. From ex1.res, send positive numbers to ex1.pos and negative numbers to ex1.neg.
  10. Calculate ((356+51)*123-12765)/56 directly on the command line.

Exercises to do after Thursday

  1. Repeat exercises 2 and 3, but this time use diff to check differences.
  2. In myfile.acc (a copy of ex1.acc), change all occurrences of SPC to BLNK using sed. Verify changes using diff.
  3. Find the path to the bash executable.
  4. Write a bash script that solves exercises 19–24, with each exercise clearly separated and explained in both the script and the output.
  5. Write a bash script that puts all positive numbers from ex1.dat into ex1.pos2 and negative numbers into ex1.neg2. The script must clean up temporary files and include a header with the date and a short description.
  6. Write a bash script that calculates the total number of lines for all files in a directory given as a command-line argument. No argument means the current directory. Note: cut can split on symbols other than tabs.

Exercises for extra practice