I need to make a script to delete files not in use in /tmp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting I need to make a script to delete files not in use in /tmp
# 1  
Old 07-04-2010
I need to make a script to delete files not in use in /tmp

I need to make a script to delete files not in use in /tmp
Thanks!

Last edited by Scott; 07-05-2010 at 08:53 AM..
# 2  
Old 07-04-2010
Were you expecting the solution in your post ? what have you done ?

Does this fit your bill?
Code:
 rm -rf /tmp/*

# 3  
Old 07-05-2010
remove files..

If you want to delete files accessed by yesterday,


Code:
A=$(date | awk '{print substr($0,5,7)}')
ls -alu /tmp | egrep -v "${A}|^total" | awk '{print "rm -rf /tmp/"$9}' | sh -


(be careful (rm -rf)...Smilie)
thank you...Smilie

Last edited by Scott; 07-05-2010 at 08:54 AM.. Reason: Please use code tags
# 4  
Old 07-05-2010
It is not advisable to remove files that have only recently been accessed as it is no guarantee that they are not actually still being used by a process. A 100% safe way is to clean /tmp (and /var/tmp) at boot time. One could use a compromise and determine an age at which a tmp file is deemed no longer in use. Best is to use the standard cleanup scripts that come with most OS'es as an init.d script these days....
# 5  
Old 07-05-2010
Have a good look at what you might be deleting in the context of your own system and its software. There is no general answer to this except as Scrutinizer suggests doing it during a reboot. Certainly confine any deletions to files (i.e. not pipes, directories etc.) and perhaps look at files which are older than your most recent boot to start with. If you have a database engine running be aware of how long it has been up an what files it creates.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to find the GB files in /tmp directory in remote server

Hi, i need help on shell scripting. Main intention of the script is step 1: ssh to remote server Step 2: cd /tmp in remote server Step 3: in tmp i want to grep only files and directories which are in GB sizes All the servers list file is - tmpsrv.txt vi tmpsrv.txt ... (17 Replies)
Discussion started by: kumar85shiv
17 Replies

2. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

3. AIX

[Solved] Not able to delete/create file in /tmp

This is AIX box and I am not able to create or delete file in /tmp though space is there root@ttcols01/ #touch /tmp/test_file touch: 0652-046 Cannot create /tmp/test_file. root@ttcols01/ #mkdir /tmp/test_dir mkdir: 0653-358 Cannot create /tmp/test_dir. /tmp/test_dir: Invalid file system... (9 Replies)
Discussion started by: solaris_1977
9 Replies

4. Shell Programming and Scripting

Need help creating a script to FTP files to a server and then delete the files that were transfered.

I am trying to FTP files to a Windows server through my Linux machine. I have setup the file transfer with no problems but am having problem deleting those files from the Linux box. My current non-working solution is below. Any ideas, anyone?? :wall: Please be gentle, I'm fairly new to this... (4 Replies)
Discussion started by: jmalfhs
4 Replies

5. Shell Programming and Scripting

Need script to remove millions of tmp files in /html/cache/ directory

Hello, I just saw that on my vps (centOS) my oscommerce with a seo script has created millions of tmp files inside the /html/cache/ directory. I would need to remove all those files (millions), I tried via shell but the vps loads goes to very high and it hangs, is there some way to do a... (7 Replies)
Discussion started by: andymc1
7 Replies

6. Shell Programming and Scripting

Script for delete tmp files older than 15 days and owned by "xxx" id

Hi All , I want to delete files from /tmp directory created by "xxxx" id. because i got the list says more than 60 thousand files were created by "xxxx" id since 2002. The /tmp directory has lot of files created by different user ids like root,system etc.. But, i need a script to... (2 Replies)
Discussion started by: vparunkumar
2 Replies

7. Linux

/var/tmp/slapd.log.swp delete?

Hi All, Can I delete the above file? It's big, about 1G. It's on a redhat ent 4 with ldap on it. Is that safe to delete? It wasn't been used for already a month and it's in the backup storage. Thanks for any comment you may add. (1 Reply)
Discussion started by: itik
1 Replies

8. Shell Programming and Scripting

Make script delete certain files

Hi, In a directory, say ~/dir is a lot of files and subdirectories. Some of the files are named res1.om res2.om ... res65.om The amount of files varies. I need a .csh script that deletes all res*.om files except the one with the highest number. Any suggestions? Thanks in... (6 Replies)
Discussion started by: pederlol
6 Replies

9. Solaris

Auto delete files in /tmp dir ???

I have a Solris 9 box my problem is when I restart my box all my files and dirs in /tmp dir will be deleted exept 2 directories I found them since installation phase !!!! How to keep my files at that dir " /tmp " even after restarting ??? (1 Reply)
Discussion started by: DarkSoul
1 Replies

10. UNIX for Dummies Questions & Answers

monitoring /tmp and /var/tmp for suspicous activity

Hello, does anyone have a script that can check the contents of the /tmp directory and for example e-mail the directory content if anything other than session files are present? Maybe there are better ways to monitor suspicous /tmp and /var/tmp activity, if so I'm listening :) (1 Reply)
Discussion started by: jamesbond
1 Replies
Login or Register to Ask a Question