Lesson 4: Perl System Commands

21/2 2005
Prev Index Next

Required reading
Beginning Perl for Bioinformaticians:
It seems that this book has nothing on this subject.

Learning Perl:
Chapter 13; p. 174-176, p. 182-184
Chapter 14; p. 192-193, p. 197 bottom - 199

Notes on mkdir, rmdir, chdir, rename, unlink, chmod and system.

Subjects covered
mkdir, which creates directories, rmdir, which removes empty directories, chdir, which go to the given directory, rename, which renames or moves files/directories, unlink which deletes files, chmod, which changes permissions on files/directories, system which submits jobs to the operating system and finally backticks/backquotes which does the same but retains the output from the job.

Necessary files to complete this exercise
To download the files to your system, just press the Shift key while you left click on the blue link. Follow the instructions.
We have reused some of the files from earlier exercises.
You can play around with these files as much as you like. If you change or destroy them, just download them again.

Remember to write #!/usr/bin/perl on the first line of your programs.

To print in the K-bar use: lpr -Pkps1 <filename>
Also, when invoking Netscape, do like this: netscape -ncols 64 &

All the following exercises have to be done in Perl

  1. These exercises are the same as the Unix exercises in lesson 1. This time you will do the same just in Perl. If you prefer, you can make one or two long programs, which does all this. Remember, you can use unix commands, they just have to be called from Perl. However, you should not use system calls to mv or cp.
  2. First list the files in the directory.
  3. Copy ex1.acc to myfile.acc.
  4. Copy ex1.dat to myfile.acc.
  5. Delete myfile.acc.
  6. Make a directory test and move the three files to it.
  7. Make a directory data and move the three files to that instead.
  8. Remove test directory.
  9. Change directory to data and confirm that you succeded.
  10. Make three new directories newtest - one inside the other, like a russian doll.
  11. Move the data directory to the innermost newtest directory.
  12. Confirm that the three files are moved along with the data directory.
  13. Copy the three files to your home (your top directory).
  14. Remove all newtest directories and data in the with a single command

This page was last updated         by Peter Wad Sackett, pws@cbs.dtu.dk