Skip to content
Snippets Groups Projects
exercises_beginner.rst 5.77 KiB

Exercises

Misc. file tools

  1. Which tool can be used to determine the type of a file?
  2. Use it on the following files/directories and compare the results:
    1. /usr/bin/tail
    2. ~
    3. ~/exercises/SRC_HUMAN.fasta

Copying / Deleting Files & Folders

  1. Navigate to your home directory
  2. In your homedirectory, create a new directory named new_dir
  3. Change into this directory, create a new empty file in there named new_file, and make sure that the file was created
  4. Duplicate this file by copying it as a new file named another_file
  5. Delete the first file new_file
  6. Also delete the directory (you are currently in) ~/new_dir. Does it work?

View Files

  1. Which tools can you use to see the first/last lines of the file ~/exercises/P12931.txt?
  2. How to only show the first/last three lines (of the same file)?
  3. How do you print the whole file on the screen?

Searching

  1. Which tool can be used to search for files or directories?
  2. Use it to find all directories in the ~/exercises directory
  3. Search for the file date in the /bin directory
  4. List those entries in the directory /bin that are bigger than 400kBytes

Misc. terminal

  1. Which two tools can be used to redraw/empty the screen?

Permissions

  1. Create a directory called testpermissions
  2. Change your working directory to testpermissions
  3. Create a directory called adir.
  4. Use the command which date to find out where the date program is located.
  5. Copy this date program into the directory adir and name it 'mydate'.
  6. Check the permissions of the copied program 'mydate'
  7. Change the permissions on 'mydate' to remove the executable permissions.
  8. Check the permissions of the program 'mydate'
  9. Change the permissions back so that the file is executable.
  10. Try running it as ./mydate or adir/mydate (depending on your current working directory)
  11. Copy a textfile from a previos exercise into adir, then change the permissions, so you are not allowed to write to it. Test this by trying to read it via cat.
  12. Then change the permissions so you can't read/cat it either. Test this by trying to read it via cat.
  13. Change your working directory to testpermissions, and then try changing the permissions on the directory adir to non-executable.
  14. What are the minimum permissions (on the directory) necessary for you to be able to execute adir/mydate?

Remote access

  1. Login to machine "sub-master.embl.de" (using your own username)
  2. Use exit to quit the remote shell (Beware to not exit your local shell)
  3. Use clear to empty the screen after logout from the remote server
  4. Use the following commands locally as well as on the remote machine to get a feeling for the different machines:
  5. Copy the file /etc/motd from machine sub-master.embl.de into your local home directory (using scp)
  6. Determine the filetype and the permissions of the file that you just copied
  7. Login to your neighbor's machine (ask him for the hostname) using your own username

IO and Redirections

  1. Use date in conjunction with the redirection to insert the current date into the (new) file current_date (in your homedirectory).
  2. Inspect the file to make sure it contains (only a single line with) the date.
  3. Use date again to append the current date into the same file.
  4. Again, check that this file now contains two lines with dates.
  5. Use grep to filter out lines containing the term "TITLE" from all PDB files in the exercises directory and use redirection to insert them into a new file pdb_titles.txt.
  6. (OPTIONAL) Upon inspection of the file pdb_titles.txt, you see that it also contains the names of the files in which the term was found.
    1. Use either the grep manpage or grep --help to find out how you can suppress this behaviour.
    2. Redo the previous exercise such that the output file pdb_titles.txt only contains lines starting with TITLE.
  7. The third column of the file /etc/passwd contains user IDs (numbers)
    1. Use cut to extract just the third column of this file (remember to specify the delimiter ':')
    2. Next, use the :ref:`pipe <pipe>` symbol (|) and sort to sort this output numerically

Putting it all together

  1. Create a new directory named myscripts in your homedirectory
  2. Create an empty file named mydate in the newly created directory
  3. Add the directory ~/myscripts to your PATH environment variable
  4. Use echo in combination with Redirection/Append to write ''date'' into the file ~/myscripts/mydate
  5. Change the permissions of the file mydate to be executable by you (and you only)
  6. Run the file mydate (it should print the current date & time). Make sure you can run it from any directory (change to your homedirectory and just type mydate).

Bioinformatics

Let's do some bioinformatics analyis! You can find the famous BLAST tool installed at /g/software/bin/blastp.

  1. Typing the full path is too cumbersome, so let's append /g/software/bin to your $PATH variable and ensure that it works by calling blastp.

  2. When you run blastp -help, you notice that it has a lot of options! Use redirections in conjunction with grep to find out which options you need to specify a input_file and database_name.

  3. Now run blastp using the following values as options:

    database_name = /g/data/ncbi-blast/db/swissprot

    input_file = suspect1.fasta