RMTF (ReMove Temp Files)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting RMTF (ReMove Temp Files)
# 1  
Old 10-19-2013
RMTF (ReMove Temp Files)

Heyas

As some applications (sed,grep,vi[m], etc) create some tempfiles, i'd changed a script to this: (sadly i cant find the original post (code) anymore (which just removed 2 'diffrent kinds'), just similar ones - forgot that as i was new to all this)
Code:
:) ~ $ cat $(which rmtf)

#!/bin/sh
#
#	sea's Script Tools: The 3rd Generation
#	File Description:	ReMove Temp Files
	script_version=0.9
#	Author:             Simon A. Erat (sea)
#	Created (y.m.d):    2011.07.24
#	Changed:            2013.08.25
#	License:            GPL v3
#
#	Help
#
	[[ "-h" = "$1" ]] && \
		echo -e "$(basename $0) ($script_version)
			\rReMoves Temp Tiles - Recursivly
			\rUsage: $(basename $0) [PATH1] [PATH2] [...]
			\r" && exit 99
#
#	Variables
#
	oldpath=$(pwd)
#
#	Display
#
	for a in "$@"
	do 
		[[ -d "$a" ]] && cd "$a"
		echo -e "Removing temp-files from: \t$(pwd)"
		find ./ -name '*~' -exec rm '{}' \; -print -or -name ".*~" -exec rm '{}' \; -print -or -name ".*.swp" -exec rm '{}' \; -print -or -name ".?outputstream*" -exec rm '{}' \; -print
	done
	cd "$oldpath"

However, Useful one should be aware of made me care/think about it, as i'd like to share it.
Do you see any dangerous stuff in there, or options to improve?

Thank you in advance

Last edited by Scott; 10-19-2013 at 10:17 PM.. Reason: Removed email address
# 2  
Old 10-20-2013
The cd is unsave - its exit must be checked! Imagine it suddenly fails with 'permission denied'...
Fix
Code:
if [[ -d "$a" ]] && cd "$a"
then
...
fi

The rm in find -exec are safe. I recommend rm -f, can avoid check-backs.
Last but not least, echo -e is not portable. Use printf instead.

Last edited by MadeInGermany; 10-20-2013 at 07:14 AM..
This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing large number of temp files

Hi All, I am having a situation now to delete a huge number of temp files created during run times approx. 16700+ files. We have never imagined that we will get this this much big list of files during run time. It worked fine for lesser no of files in the list. But when list is huge we are... (7 Replies)
Discussion started by: mad man
7 Replies

2. Shell Programming and Scripting

Backup shell script created temp files .

Hi, I've a script which creates a temp flat file for storing all business dates received on a single day from diff control files sent by source system on that day. e.g on 12th april I receive txns for business day 8,9,10,11 april. I capture this business day and append to a flat file from... (1 Reply)
Discussion started by: manojg9
1 Replies

3. OS X (Apple)

Safari Temp Internet Files Location

I'm looking for help with finding where plugin data and other page resources are stored on the hard disk in safari 6.0. With the new update, the activity window has been merged into the develop menu under "show page resources" and one cannot access them directly. I tried running opensnoop to see... (3 Replies)
Discussion started by: sakurashinken
3 Replies

4. Shell Programming and Scripting

Script to temp create files more than inode limit

HI, I am from testing background. I have a scenario of a file generation, through cronjob, on a defined path. After I fill the data as 100 % utilized, my application is generating an empty file on the defined path. # df -kh Filesystem Size Used Avail Use% Mounted on... (3 Replies)
Discussion started by: atulbassi83
3 Replies

5. Shell Programming and Scripting

temp files

Hi there, As a regular unix user I am forever programming on the command line or writing scripts so that I first write a load of data to a file to read from. In the end I am always left with a bundle of .txt, .tmp which is what I usually call them. As a basic programmmer I was wondering is... (6 Replies)
Discussion started by: cyberfrog
6 Replies

6. UNIX for Dummies Questions & Answers

Temp mysql files jamming CPU resources

Hello Friends I am currently facing high CPU usage problem which is making my site extremely slow. Currently I am using a 8GB RAM with 8 cores but, the creation of temporary files is eating away a lot of the CPU resource making the site very slow. The normal CPU load average remains below 2-3... (5 Replies)
Discussion started by: egully
5 Replies

7. Shell Programming and Scripting

Joining 3 AWK scripts to avoid use "temp" files

Hi everyone, Looking for a suggestion to improve the below script in which Ive been working. The thing is I have 3 separated AWK scripts that I need to apply over the inputfile, and for scripts (2) and (3) I have to use a "temp" file as their inputfile (inputfile_temp and inputfile_temp1... (2 Replies)
Discussion started by: cgkmal
2 Replies

8. UNIX for Dummies Questions & Answers

Security issue and temp files

Hello, One of the senior network admins at work told me that I should not hard code temp files into my scripts. Rather I should use the mktemp commands in the script to create them on the fly. His argument was that if a malicious user knew the name of my temp files in the script they could... (6 Replies)
Discussion started by: mojoman
6 Replies

9. Shell Programming and Scripting

Script to Delete temp files and check file system

Hi all, new to the threads as well as Unix/Linux. I need to create a script that will delete any temporary files as well as check the files on the system for errors or corruption. This is what I have so far and I'm sure that I'm missing things or have the wrong commands. I'm not sure where to go... (3 Replies)
Discussion started by: Bwood1377
3 Replies

10. UNIX for Dummies Questions & Answers

Tidying up temp files on exit of script

Hi I believe there is a method to remove all temporary files when a KSH script terminates (either expectedly or unexpectedly). I think is some sort of subroutine you can create that runs when the script exits. Can anyone help me with this please? Many thanks Helen :confused: (2 Replies)
Discussion started by: Bab00shka
2 Replies
Login or Register to Ask a Question