Deleting a type of file in a directory immediately it occurs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting a type of file in a directory immediately it occurs
# 1  
Old 08-10-2011
Deleting a type of file in a directory immediately it occurs

Hi All,
I have to maintain few servers and in those servers in a specific directory some special jobs keeps on running .......
The directory is having many kind of files like.....acd*, hud*, rca*....bla bla bla.......

My aim is that if due to any job-any time a file having initials like rca* occurs in that directory it automatically gets deleted at the same moment.....

Kindly suggest how to achieve this......thanx in advance..............
# 2  
Old 08-10-2011
If you are on linux, have a look at inotifywait
# 3  
Old 08-12-2011
Dear I try by this code......

#!/bin/sh
while inotifywait -m -e create /$HOME/ext/cbe/output/pps/normal/temp/
do
rm *.csv
done

but after 1 deletion the script is getting stopped.....I want the watchdog to be maintained, and it keeps on running in background until the process is killed manually....
# 4  
Old 08-12-2011
Try this, I could not get yours to run for some reason:

Code:
#!/bin/bash -x
inotifywait -m -e create /$HOME/ext/cbe/output/pps/normal/temp|while read line
do
if [[ $line =~ "csv" ]]
then
rm *.csv
fi
done

# 5  
Old 08-13-2011
Quote:
Originally Posted by jitendra.pat04
Dear I try by this code......

#!/bin/sh
while inotifywait -m -e create /$HOME/ext/cbe/output/pps/normal/temp/
do
rm *.csv
done

but after 1 deletion the script is getting stopped.....I want the watchdog to be maintained, and it keeps on running in background until the process is killed manually....
Try putting an extra
Code:
while : ; do
...
done

loop around it. I would explicitly specify the directory, instead of deleting in the working directory..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find directory immediately after the pattern dir name

Hi, From below directories path I need the directory which comes immediately after the "DataPath" /var/errors/LogDefaultPath/DataPath/Data01/Data02 (Directory name "Data01" is the result from this path) /var/errors/LogDefaultPath/DataPath/Log01/Log0202 (Directory name "Log01" is the... (4 Replies)
Discussion started by: Yuvaan12
4 Replies

2. UNIX for Dummies Questions & Answers

Deleting a directory and zipping another directory

Hi Folks, I have a directory in unix that is /usr/local/pos contain the folowing directoreis ..that is dir1 dir2 dir3 now I want to delete only dir2 please advise how to remove the directory dir 2 ..that is rm command and how to use it , and second if I want to zip the dir3 please... (1 Reply)
Discussion started by: punpun66
1 Replies

3. Shell Programming and Scripting

Deleting all files recursively from directories while ignoring one file type

Hi, Seems like I need help again with a problem: I want to delete all files from my lets say "Music" Directory inkluding all of the subfolders except for .mp3 and .MP3 files. I tried it with globalignoring mp3 files, finding and deleting all other files, which resulted in all files... (3 Replies)
Discussion started by: pasc
3 Replies

4. Shell Programming and Scripting

Deleting the oldest file in a directory

Hey! I have found similar posts both here and on other sites regarding this, but I cannot seem to get my script to work. I want to delete the oldest file in a test directory if there are more than two files. My script is currently: #!/bin/bash MEPATH=/usr/local/bin/test FILECOUNT=`ls... (4 Replies)
Discussion started by: Immolation
4 Replies

5. UNIX for Advanced & Expert Users

Deleting older files of a particular type

hi This should be easy but i'm obviously missing something obvious. :) I'm looking to delete files from yesterday and older of extension .txt and there a range of subfolders with these files in them. The command runs but doesn't delete anything. SUSE 10. find /testfolder -maxdepth 2 -type f... (6 Replies)
Discussion started by: cmap
6 Replies

6. Shell Programming and Scripting

Need to extract 7 characters immediately after text '19' from a large file.

Hi All!! I have a large file containing millions of record. My purpose is to extract 7 characters immediately after text '19' from this file (including text '19') and save the result in new file. So, my OUTPUT would be as under : 191234561 194567894 192789005 198839408 and so on..... ... (7 Replies)
Discussion started by: parshant_bvcoe
7 Replies

7. Shell Programming and Scripting

Deleting the file only to all the directory and sub directory

I need the unix command or shell script to delete all the file in current directory and sub directory. (7 Replies)
Discussion started by: kingganesh04
7 Replies

8. UNIX for Advanced & Expert Users

Deleting the file except one type of file

I need the unix command which is used to delete the file except one the of file format. example: In folder a.txt b.txt c.prn d.st g.lg Output : except .st files remaining all are deleted from the folder. (7 Replies)
Discussion started by: kingganesh04
7 Replies

9. UNIX for Dummies Questions & Answers

deleting files by type (symbolic links)

How do I delete just the symbolic links in a directory? I have files that I wish to keep that have similar names, length and date/time. Can I use file size? Thanks kyle (4 Replies)
Discussion started by: kryan_toolboy
4 Replies

10. Programming

problem deleting date-time stamped file in a directory

I have a number of files of the format filename.xfr_mmddyy_%H%M%S which i get in a specified directory daily. Now i want to search in the specified directory & delete the files which are more than 2 days old .So I use a command find $DIR/backup/* -ctime +2 -exec rm -f {} \; But after executing... (1 Reply)
Discussion started by: dharmesht
1 Replies
Login or Register to Ask a Question