rm command-outputting files as they are deleted?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers rm command-outputting files as they are deleted?
# 1  
Old 06-15-2010
rm command-outputting files as they are deleted?

Solaris 10/Korn

Hi unix experts!,

Is it possible to output the actual file names to a file as they are being deleted via the rm command?


Context:
Im executing the shell script at the command line and directing the output to an output file eg purgescript.ksh > output.lst

within the file Im using the following find command to remove files.


find $EXP_DIR -mtime +$RETENTION_PERIOD -exec rm {} \;

where $EXP_DIR and $RETENTION_PERIOD period are respective parameters passed in

but the output.lst file does not show the files being removed. Is there any way to output this?

Kind regards
Satnam
# 2  
Old 06-15-2010
Code:
find $EXP_DIR -mtime +$RETENTION_PERIOD -print -exec rm {} \;

# 3  
Old 06-15-2010
In this approach we pipe a list to a routine which does the deletions.
It also lets you test what will be deleted first.

Code:
find "${EXP_DIR}" -type f -mtime +${RETENTION_PERIOD} -print | while read FILENAME
do
        echo "Deleting: ${FILENAME}"
        if [ -f "${FILENAME}" ]
        then
                 # Remove echo when tested
                 echo rm "${FILENAME}"
        fi
done


Note: The "if -f" allows for strange filenames which would require special action.
# 4  
Old 06-15-2010
very useful suggestions!

much appreciated.

regards
Satnam
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Comparing fastq files and outputting common records

I have two files: File_1: @M04961:22:000000000-B5VGJ:1:1101:9280:7106 1:N:0:86 GGCATGAAAACATACAAACCGTCTTTCCAGAAATTGTTCCAAGTATCGGCAACAGCTTTATCAATACCATGAAAAATATCAACCACACCAGAAGCAGCAT + GGGGGGGGGGGGGGGGGCCGGGGGF,EDFFGEDFG,@DGGCGGEGGG7DCGGGF68CGFFFGGGG@CGDGFFDFEFEFF:30CGAFFDFEFF8CAF;;8F ... (3 Replies)
Discussion started by: Xterra
3 Replies

2. UNIX for Dummies Questions & Answers

Outputting 1 file per row if pattern exists between files

I have many files that can have various amounts of rows. I essentially want to output each row into a new file if a pattern is matched between two files. I have some code that does something similar but I want it to output every single input row from every file into a separate output file; that... (5 Replies)
Discussion started by: verse123
5 Replies

3. UNIX for Advanced & Expert Users

CVS command to revert deleted files

Hi, I have deleted a file and commited in CVS. So, is there any CVS command to revert back that deleted file with existing log messages. --Thanks in advance Madhu (1 Reply)
Discussion started by: madhuti
1 Replies

4. UNIX for Dummies Questions & Answers

Sz command hanging and outputting ZNAK’s

Currently I am using the following sz and rz commands to run file transfer using ZMODEM within a perl script. sz -b -m1 -M2 -k -e -r -u -t10 rz -b -m 1 -M 120 -y Is there any flag setting that will allow me to terminate when a retry 0 error is outputted as this is constantly filling up my... (0 Replies)
Discussion started by: M1keSt4r
0 Replies

5. Shell Programming and Scripting

write a perl script or kornshell reading a two files and outputting to comma format

Hello Can someone help me to write a perl script or kornshell reading a two files and outputting to comma format. Here is the two files listofdisks.txt id, diskname, diskgroup, diskisze(GB), FC 1, CN34, GRP1, 30, FC_CN34 2, CN67, GRP5, 19, 4, VD1, GRP4, 23, FC_VD1 6, CF_D1, ... (0 Replies)
Discussion started by: deiow
0 Replies

6. Linux

how to get passwd command again if it is deleted by usin rm command

hai friends i have deleted passwd command using rm command i thought it will come again at the time of rebooting but it is completely deleted how to get it worked again (5 Replies)
Discussion started by: venkata.ganesh
5 Replies

7. Shell Programming and Scripting

How to deleted a string using tr- command

I have a file like below 4 0 /work/ram/jagan/irt_XXrules.dat 4 0 /work/ram/jagan/irt_NNrules.dat 4 0 /work/ram/jagan/irt_MMrules.dat 4 0 /work/ram/jagan/irt_ZZrules.dat My output should be 4 0 XXrules 4 0 NNrules 4 0 MMrules 4 0 ZZrules (3 Replies)
Discussion started by: suresh3566
3 Replies

8. Shell Programming and Scripting

Help in outputting the result in log files

This is the file am having: "40","1G1AL55 ",30482,9000 "40","1G1ZT58 ",29098,10600 "40","1G1AL15 ",29222,9400 "46","1G6KD57 ",3083,28400 "46","1G6KD57 ",27909,25200 "49","1G1ZU57 ",16391,13900 "49","1G2ZG58 ",28856,12400 I want to display the output in three files... (23 Replies)
Discussion started by: dave_nithis
23 Replies

9. Shell Programming and Scripting

Is there a way to recover files deleted using rm command???

Hi All, I just mistakingly deleted some files using rm command.Is there a way to get it back?i work on Solaris 10 Thanks, Kumar (1 Reply)
Discussion started by: kumarsaravana_s
1 Replies

10. Shell Programming and Scripting

Outputting from two input files.

Ok, lets suppose I have two files like so: file1 John 5441223 Sandy 113446 Jill 489799 file2 Sandy Tuesday Jill Friday John Monday Is it possible to match records from these two files and output them into one output file? For example, lets suppose I want to output like this: ... (5 Replies)
Discussion started by: Liguidsoul
5 Replies
Login or Register to Ask a Question