Sponsored Content
Full Discussion: Find modify and delete files
Top Forums Shell Programming and Scripting Find modify and delete files Post 302853863 by zaxxon on Monday 16th of September 2013 09:06:44 AM
Old 09-16-2013
If it is working, it's just what you asked your friend for.
Why don't you ask your friend? Smilie

Next time, be more precise which part you do not understand instead, thanks.

Code:
#!/bin/bash

Use bash explicit as interpreter to run this script

Code:
START="a.txt"
END="b.txt"
DIFF="c.txt"

Define 3 variables with a file name.

Code:
mv ${START} ${END} #moving the first file to be compared

Renames the start file to the name of the end file. If it already exists, it is overwritten. Saves the data in the file from the previous run to b.txt so they are not lost and can be compared with actual data.

Code:
find /home -type f -mmin -5 -print > ${START}

Find files in directory /home that are not older than 5 minutes and write their path and name into the file a.txt.

Code:
diff ${START} ${END} | grep '<' > ${DIFF}

Find the lines that are different from the old file b.txt and write them to the file c.txt.

Code:
COUNT=$(cat ${DIFF} | wc -l)

Count the number of different lines.

Code:
if [[ -s ${DIFF} ]] ; then
     cat -- ${DIFF} | mail -s "Modified files in last 5 minutes *** ${COUNT} ***" root
fi

Check if the file c.txt exists and has a size greater 0.
If this is the case, tell cat to not accept any switches and send a mail with the subject "Modified files..." where the mail's body is the cat'ed different lines to root.

Last edited by zaxxon; 09-16-2013 at 02:31 PM.. Reason: messing around with code tags
This User Gave Thanks to zaxxon For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

batch delete using find, files with # character

UPDATE: Sorry, disregard this. It did work, I made a mistake; I just shouldn't have been using maxdepth. I do think it is good to know, however, that find | grep '#' | xargs rm will "clean up" funnily named files in a directory. Of course, some of those funnily named files are there... (0 Replies)
Discussion started by: tphyahoo
0 Replies

2. Shell Programming and Scripting

Find files including subdirectory and Delete

Hello Experts, I m newbie. Could u pls help me to write script on Sun solaris- I have backup directory "/var/opt/backup/" where files are backed up in different directory "backup1" "backup2" "backup3". I want to write a shell script which i will put in crontab and daily midnight it will... (1 Reply)
Discussion started by: thepurple
1 Replies

3. UNIX for Dummies Questions & Answers

find and delete files

hi all , i want to find and interactively delete all the files having size greater than 20 bytes using "find" and other commands..... (8 Replies)
Discussion started by: sonu_pal
8 Replies

4. Shell Programming and Scripting

find files for a particular date and delete

How can I delete files for a particular date ? I apologize in advance If there is solution please put the link. Thanks, (5 Replies)
Discussion started by: jville
5 Replies

5. Shell Programming and Scripting

Script to find files and delete it by comparing

I have a directory where lot of "gzip" files are dropped in every 5 minutes. There is an application which will process these gzip and move it to another directory but will leave a gzip.out file with lot of output data. I need to remove all the outfiles except for the one which is being... (1 Reply)
Discussion started by: gubbu
1 Replies

6. Homework & Coursework Questions

Find and delete empty files and directories

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Need to make a script, to remove all empty files and folders from current category. It also should show the name... (2 Replies)
Discussion started by: Itixop
2 Replies

7. UNIX for Dummies Questions & Answers

Script to find the files and delete them

This is a real world problem so I think you might found this interesting. We have servers which are shared by multiple team members. Each team member has its own user id and home directory. Now with time each user starts creating files which in end caused the disk to be full. Now for creating a... (5 Replies)
Discussion started by: Rohit06
5 Replies

8. Shell Programming and Scripting

Script to go Into Directories and Find/Delete files

I have a task, I usually do manually, but with growing responsibilities I tend to forget to do this weekly, I want to write a script that automates this, but I cant seem to work it out in my head, I have the shell of it out, but need help, and you guys have helped me with EVERY problem I have... (5 Replies)
Discussion started by: gkelly1117
5 Replies

9. UNIX for Dummies Questions & Answers

Find command to delete old files

Hi, I want to delete all the log files that was created on year 2008. My command is not working. Any idea? find . -name '*.log' -mtime 1460 -exec ls -lt {} \; Thank you. (2 Replies)
Discussion started by: samnyc
2 Replies

10. Shell Programming and Scripting

Find command to delete the files

Hi All, I've created 2 files touch -t 201309101234 aa10 touch -t 201309111234 aa11 Exact 60 days before from today date is SEPT 12th . As per the following command as i gave +60 means the files which were created before sept12th should be deleted find /etc/logs/*aa* -type f -atime +60... (5 Replies)
Discussion started by: smile689
5 Replies
All times are GMT -4. The time now is 08:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy