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 posted, and have found help in others posts as well. Please see below shell code I have started. I want to go to the ORDATA which is the variable for /opt/data in this case directory, find the folders with most stuff in it and cd into each one and then cd into the backup folder and do a couple of those find commands.
How do I make it go out of the first directory and into the next and so on and so forth? I know i can use the while loop in some capacity, but not quite sure.
for example /opt/data/ has 4 directories /mpw, /docprep, /edfiles, /vgdata and under each of those directories is a /backup directory as well, I want to start at /opt/data, go into each the 4 directories, go into the backup directories and do those find and delete commands i came with until its went into all 4 backup directories.
Below is what I have so far.
Last edited by gkelly1117; 04-03-2013 at 12:08 PM..
Reason: Bad title
Per our forum rules, all threads must have a descriptive subject text. For example, do not post questions with subjects like "Help Me!", "Urgent!!" or "Doubt". Post subjects like "Execution Problems with Cron" or "Help with Backup Shell Script".
The reason for this is that nearly 95% of all visitors to this site come here because they are referred by a search engine. In order for future searches on your post (with answers) to work well, the subject field must be something useful and related to the problem!
In addition, current forum users who are kind enough to answer questions should be able to understand the essence of your query at first glance.
So, as a benefit and courtesy to current and future knowledge seekers, please be careful with your subject text. You might receive a forum infraction if you don't pay attention to this.
Appreciate it alot, let me play with this a little bit, question, Can I feed this multiple directories, I remembered I also have a tmp directory and files under ordata in a different structure tree other than /backup that fills quickly, so can i add
etc.. after that first find? It makes sense to me that it could, just want confirmation.
Yes, we can.
If your find statements are exactly the same otherwise, you can combine them to one
I changed the order, so the more "expensive" name comparison is after the simple file type and age checks. -a (AND) is only for readablity - can be omitted.
Last but not least, this should be secured:
This User Gave Thanks to MadeInGermany For This Post:
Hello,
I need help in writing the shell script for below mentioned case.
There are 2 servers(server A, server B).
A cronjob syncs files between these 2 servers.
Existing script is copying files from A to B.
This is done using the command rsync.
However, the files are not deleted... (2 Replies)
Hello,
I'm trying to figure out how best to approach this script, and I have very little experience, so I could use all the help I can get. :wall:
I regularly need to delete files from many directories.
A file with the same name may exist any number of times in different subdirectories.... (3 Replies)
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)
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)
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)
Hello
I have some directories and files created under /export/local/user
I would like to delete directories only under /export/local/user, created before 3 days
Can someone help me with command to do this task?
Thanks (4 Replies)
Hi
I need a script that can search through a set of directories and can locate any file or directory that has a space at the end
Filename(space)
Foldername(space)
I then need to remove that space within the script
Hope someone can help
thanks in advance
Treds (8 Replies)
Hi,
I have dummies questions:
My script here can find the files in any directories older than 30 days then it will delete the files but not the directories. I would like to also be able to delete the directories that hold old files more than 30 days not just the files itself.
find . -type f... (2 Replies)
################################################################
Copy this script to your path from where you want to search for all the files and directories in subdirectories recursively.
#################################################################
code starts here... (2 Replies)
Hi people.
I working on a script to check for files that they are suposed not to be on the directory. I mean, inside of each directory it must have some files but some could be wrong, and i want to move the files that are wrong.
Ex:
CSPOTGET edpst/CargadoresSPOT Historicos_Spot_MDI.zip... (4 Replies)