I'm trying to write a script that finds and deletes files that are older than 300 days. The script will read a table that contains the following 3 columns:
1st col: “Y” means sub-directory scan; "N" means no subdirectory scan
2nd col: sub-directory location
3rd col: File prefix (* indicates all files)
For ex:
Y|/data/informatica/ming/Logs|*
N|/data/informatica/ming/ScriptsLogs|*
N|/data/sw/apps/informatica8/JBoss403/bin/|heapdump*.phd, javacore*.txt
Reason I'm using a table is that the list of directories can grow and I'm trying to avoid hard-coding anything in the script.
I have searched the forum but I haven't been successful in finding any examples on what I am trying to accomplish.
I have tried the following with the find command so far:
-prune option (but this requires hard-coding the sub-directories)
-maxdepth 1 (option does not work in my environment)
ls -l | grep -v ^d (not sure how to use this in conjuction with the find command)
In addition, the 3rd example from my table:
N|/data/sw/apps/informatica8/JBoss403/bin/|heapdump*.phd, javacore*.txt
How can I dynamically parse the 3rd field to scan for these files since there could be more files added to the 3rd field column in the future?
I believe that the script offered by aigles will have issues because the OP indicates that the 'sub directory location' is a full path, and the -name option (according to the man page) takes a basename, not a path name.
Instad of the -name option the -path option should be used.
This script needs only one pass over the filesystem and defaults to listing the files. Supply 'rm' as the parameter to the script and the files will be deleted:
Thank you guys for your quick responses and proposed solutions.
I will have a look at each one and try them out.
---------- Post updated at 04:14 PM ---------- Previous update was at 10:37 AM ----------
Hi Guys.
I finally had a chance to test out the 3 proposed solutions and here are some results:
ygemici - maxdepth option does not work in my environment aigles - script does not work when a full path is provided. My table will contain the full paths of the directories that I would like to cleanup. How can the script be modified to accept full path directories? agama - How do I go about embedding your code into a script?
Copied entire code just prior to the last pipe into a new script member test.sh - how to execute the script to read my table pchang.dat?
agama - How do I go about embedding your code into a script?
Copied entire code just prior to the last pipe into a new script member test.sh - how to execute the script to read my table pchang.dat?
Sorry -- I failed to realise that the testing I was doing was reading the table in from stdin and thus no filename was presented to awk and thus my info wasn't percise.
You can either redirect the table into your script like this:
or pass the table name on the command line, and use add a $1 following the last single quote of the awk programme.
My recommendation would be the first way. If you use the second, then you should add a test in your script and generate an error message if the user forgets to put the table name on the command line.
The output will be the find commands, they won't be executed unless you pipe them into Kshell or bash. You can put the pipe into the script, or pipe the output manually -- I do this sometimes so that I can verify the commands before I execute them.
Hi,
uname -a
SunOS mymac 5.11 11.2 sun4u sparc SUNW,SPARC-Enterprise
I need to tar a folder /tmp/moht but do not want these three folders to be included in the tar file -> savejpg, bmpsave and imgsave
I tried --exclude, -path, -not options but it says bad option
Can you help me with... (3 Replies)
Can you please help tweak the below command to exclude all directories with the name "logs" and "tmp"
find . -type f \( ! -name "*.tar*" ! -name "*.bkp*" \) -exec /usr/xpg4/bin/grep -i "user_1" /dev/null {} + >result.out
bash-3.2$ uname -a
SunOS mymac 5.10 Generic_150400-26 sun4v sparc sun4v... (9 Replies)
Hi, im having some issues after i execute the next command:
tar -cvf /varios/restore/test.tar -X /jfma/test1/excludefile /jfma | gzip -c > /varios/restore/test.tar.gz
this creates the desired "test.tar.gz" file, but whe i try to open it it says "tar: 0511-164 There is a media read or write... (6 Replies)
Hi all,
Using grep command, i want to find the pattern of text in all directories and sub-directories.
e.g: if i want to search for a pattern named "parmeter", i used the command
grep -i "param" ../*
is this correct? (1 Reply)
Hi,
Firstly - sorry for the duplicate my other post looked like i was posting a how to for people. But i am wanting some help :P
I want to search from / to find files and exclude my mounted ntfs drives.
I have found this thread (Which I can't post the URL to until i have 5 posts) it's... (4 Replies)
Hi,
I use find command to list all the files in a directory and its sub-directories, but the problem is to exclude certain directories during search. Can i give the directory names in command line to skip them and search rest of the directories?
For example i have directories:
test
../test1... (1 Reply)
Hi,
Can some one help me how to exclude multiple directories using find command..
I have the directory structure below.
/a/a1/b1
/a/c1/c2
/a/d1/d2/d3
I want to exlcude a1,c2and d3 from the above using find,can some one suggest pls..
thanks in advance...
Use code tags... (1 Reply)
Hello,
I have a line in my script to find the files changed in the last 24 hours. It is as below:
find /home/hary -type f -mtime -1
I now want to exclude a directory named "/home/hary/temp/cache" from the above find command. How do I add it to my script?
Any help is appreciated.
... (9 Replies)
Howdy
I have this directory structure ...
eep
eepaptest
eepfatest
eepgltest
eep.old
eeppoptest
ehf
ehfaptest
ehfgltest
ehp
ehpgltest
I want to find files in these directories, but I want to exclude eep, ehf & ehp.
Cany anyone help with the correct command ?? (1 Reply)