Deleting newly created files

Asked by avkapur

When I run this program it takes, for example, the filename TargetGenes2000unmasked.fasta. When the program runs it creates 4 different files such as TargetGenes2000unmasked.fasta.cat, TargetGenes2000unmasked.fasta.out, TargetGenes2000unmasked.fasta.tbl, Targetgenes2000unmasked.fasta.masked, and a folder called TargetGenes2000unmasked.fasta.out, and .masked all of which are useless except the last file which was TargetGenesunmasked.fasta.masked. Since I will be running the program for different filenames such as TargetGenes1500unmasked.fasta is there a way to tell unix to delete any newly created files automatically. Would appreciate any help. Thanks.
Amit

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
Harvey Muller
Solved:
Last query:
Last reply:
Revision history for this message
Bhavani Shankar (bhavi) said :
#1

Hmm I think that cant be done as there are different file formats

you can use sudo rm -i <file name>

to delete specific file

Regards

Revision history for this message
Harvey Muller (hlmuller) said :
#2

avkapur,

The solution is to create a shell script which runs the initial program, and then deletes the files you do not want.

Here's an example of simple script which should resolve your need:

===BEGIN SCRIPT===
#!/bin/sh
# rundelete

PROGRAM=/path/to/program
TARGET=$1

# Run the program

$PROGRAM $TARGET

# Delete the extraneous files and directories

rm $TARGET.cat $TARGET.out $TARGET.tbl

rm -rf $TARGET.out .masked
===END SCRIPT===

Copy the script above into a text editor and save it as rundelete, or whatever you want to name it. Then to make it executable in a terminal run:

    $ chmod 755 rundelete

Then to run it:

    $ ./rundelete

The script is very basic, and does absolutely no error checking. But it should give you the general idea, and a good base to start from.

If this resolves your question, please return to Launchpad and mark this question Solved.

Thanks!

Harvey

Revision history for this message
Harvey Muller (hlmuller) said :
#3

avkapur,

I failed to mention that the command to start should read:

    $./rundelete <filetoprocess>

You would replace <filetoprocess> with the file you are processing.

Thanks,

Harvey

Revision history for this message
Best Harvey Muller (hlmuller) said :
#4

avkapur,

One final thing. You would replace /path/to/program with the actual path and name of the program.

Thanks,

Harvey

Revision history for this message
avkapur (avkapur) said :
#5

Thank you for all the help.
-Amit