please help me how to script atomatic remove file that are not needed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting please help me how to script atomatic remove file that are not needed
# 1  
Old 08-23-2007
please help me how to script atomatic remove file that are not needed

Im new to this forum and also Unix.
I need help to solve this Directory Clean-up. Im not sure how to do but i wish someone could help me out.

I have to develop a script that can be used to automatically remove files that are not needed. The final script will be developed in two iterations. The initial script will delete based on a fairly rigid set of criteria. The advanced script will use tools to increase the chances that files that are deleted really are surplus to requirements.

A continuing problem with computer systems is the management of hard disk space. There are several
reasons for this. One reason is that users typically have a great deal of inertia with respect to actually
deleting un-needed files. Another reason is that a number of programs automatically create backup files
without asking permission first. And, finally, when a program terminates abnormally, Unix generates a
core file by default to aid in debugging the cause of the termination.

Basic Script
The first script will accept as its command line argument the name of the starting directory in either
absolute or relative notation. (e.g. If the present working directory is /home and we wanted to process
directory /home/foo and all of its sub-directories, the command line could be:
Code:
cleanup /home/foo or
cleanup foo or
cleanup ./foo

All three forms must work.)
This basic script should remove files with names that end in:
Code:
.bak
~
.BAK
#

And files with the name core.

Advanced Script
When looking for corefiles, include any file with core in its name. (Some Unix/Linux systems add
the pid of the process that created the core to reduce the chances of overwriting an already existing
core file that might be needed.
But since the above criterion may be just a bit too inclusive, use the file command to make sure it
really is a core file.
Look for files that were last accessed more than a user-setable number of days in the past. Remove
these files.
An additional enhancement to the core deletion that you may wish to attempt is to add a test that
looks for the relevant executable file using a system path, and only deletes the core if the program
that crashed is in the path. So a program that the user was developing would probably not be in the
path and the core file would be retained.
An enhancement to the “delete unused files option” above would be to look for files that were last
accessed more than a user-setable number of days in the past. Put the name of the file into a list.
Use GNU tar to archive and compress the files in the list. Then remove the files. (Note, the archive
name should include the date so that an existing archive would not be overwritten. Given that the
Unix filesystem commands do not do well with spaces in filenames, find a way of inserting the date
without spaces.)
Still more enhancement, use a fixed archive name and, if the archive file already exists, simply add
the new files to the archive instead of either creating a new archive or overwriting the old one.
Another possible enhancement would be to add a way of specifying a directory structure and deleting
all regular files in the directory recursively, while leaving the directories. This might be useful to
reduce the space used by web browsers for their cache structure.
A final enhancement to consider would be to modify the script so that it has a list of filename
extensions for backup files in a shell variable. Then, a new type of backup file would only require an
addition to this list.


my mail address is : email address removed

please guys help me

thanks in advance

Last edited by vino; 08-23-2007 at 05:25 AM.. Reason: Removed email address.
# 2  
Old 08-23-2007
get familiar with find command and all its usage, this will help you.
For example,
Code:
find /path/to/dir/ -maxdepth 1 -name "*.bak" -exec rm {} /

would delete all files in /path/to/dir/ that have names ending with .bak
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script needed to extract few lines from file

Hello, I need a utility script or command that will extract the following lines from a file based on a 'word' contain in a line. For example my file contains lot of lines. So if i pass 1800182 to the script/command it should return everything between 1st RequestNetRates tag before it and 1st... (4 Replies)
Discussion started by: jakSun8
4 Replies

2. Shell Programming and Scripting

Needed script for the version file

I need some help with the logic and syntax for a shell script (ksh) that will search a directory and look for similar files and save only the 5 versions. The version number is in the file name. However, the files are of varying name lengths and may have 1 or many files, with no limit to the... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

3. Shell Programming and Scripting

Needed script to FTP a File and generate a quality checksum file

hi all i want a script to FTP a file and should generate a quality checksum file means when I FTP a file from one server to another server it should generate a QC file which should contain timestamp,no.of records in that file Thanks in advance saikumar (3 Replies)
Discussion started by: hemanthsaikumar
3 Replies

4. Shell Programming and Scripting

Help needed with File Watcher script

Hi all, I am writing a script to do the following: 1) Check if there are any new <csv> files (in abc directory) to process 2) If there is new file, then perform some operation on that file. 3) Move it to a different location(after step2 is successful) 4) Do further processing on the file ... (2 Replies)
Discussion started by: stunnerz_84
2 Replies

5. Shell Programming and Scripting

KSH - help needed for creating a script to generate xml file from text file

Dear Members, I have a table in Oracle DB and one of its column name is INFO which has data in text format which we need to fetch in a script and create an xml file of a new table from the input. The contents of a single cell of INFO column is like: Area:app - aam Clean Up Criteria:... (0 Replies)
Discussion started by: Yoodit
0 Replies

6. Shell Programming and Scripting

Conversion of below Tabs Tex file into CSV format file : shell script needed

Request if some one could provide me shell script that converts the below "input file" to "CSV format file" given Name Domain Contact Phone Email Location ----------------------- ------------------------------------------------ ------- ----- ---------------------------------... (7 Replies)
Discussion started by: sreenath1037
7 Replies

7. Shell Programming and Scripting

shell or perl script needed for ldif file to text file conversion

This is the ldf file dn: sdcsmsisdn=1000000049,sdcsDatabase=subscriberCache,dc=example,dc=com objectClass: sdcsSubscriber objectClass: top postalCode: 29600 sdcsServiceLevel: 10 sdcsCustomerType: 14 givenName: Adelia sdcsBlackListAll: FALSE sdcsOwnerType: T-Mobile sn: Actionteam... (1 Reply)
Discussion started by: LinuxFriend
1 Replies

8. Shell Programming and Scripting

Help needed in script and sql file

Hi all, I have a script which takes in sqlfile as argument and executes the sql execSqlFile() { sqlFile=$1 sqlplus -S $DBLOG/$DBPWD@$DBSVR < $sqlFile } This works fine if the sql file is plain, simple and pre-defined statment. But i want to have a sql file which itself... (2 Replies)
Discussion started by: jakSun8
2 Replies

9. Shell Programming and Scripting

Remove a File - Help Needed

Hi, I have created a file "-f.txt" or "-f" and now i want to remove this file, I have tried rm -f -f, but you would have understood the problem i am facing. Now please let me know what needs to be done, Also one more question i want to know the difference between Hard Link and Soft Link and... (3 Replies)
Discussion started by: amitkhiare
3 Replies
Login or Register to Ask a Question