LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-30-2009, 01:04 PM   #1
Iyyappan
Member
 
Registered: Dec 2008
Location: Chennai, India
Distribution: CentOS 5, SLES 11
Posts: 235

Rep: Reputation: 4
script to delete tmp files


we have 2 linux desktop m/c as server and we use amc n windows as clients....we get more temp files like .AppleDoueble, ":2edstore"......i need to remove these temp files periodically with the help of script.....can anyone give ideas on how to write a script to remove these temp files.....
 
Old 07-30-2009, 01:10 PM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
Where are the files located?
Do they end at .tmp or .temp?
Code:
#/usr/bin/find /directory_of_the_files -name filename.tmp -exec /bin/rm {} \;
 
Old 07-31-2009, 04:36 AM   #3
centosboy
Senior Member
 
Registered: May 2009
Location: london
Distribution: centos5
Posts: 1,137

Rep: Reputation: 116Reputation: 116
Code:
find /directory/of/temp/files -name '*.tmp' -delete
 
Old 07-31-2009, 01:14 PM   #4
Iyyappan
Member
 
Registered: Dec 2008
Location: Chennai, India
Distribution: CentOS 5, SLES 11
Posts: 235

Original Poster
Rep: Reputation: 4
Reg: Temp files

.appled* and appledouble* files gets created in all the Folders that are accessed by the users. we have installed netalk in linux for the mac userss to acces the linux server....these temp files gets created whenever we go inside any of the folders.... i used to manually remove these files evry now n then.....i dont know abt scripts .. i just started to learn about it...but i need a script to remove these files.


i use rm -rvf .AppleD* to remove files in a folder which is of 140 gb..but still many files of these dont get removed, i need to get to the nearest folder to remove these temp files....the problem is we have big folder structure......these temp files get removed in the parent folders and child folders but not in the sub sub folders of the child folders.........
 
Old 07-31-2009, 01:19 PM   #5
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
Try

Code:
find / -name .AppleD* -exec /bin/rm {} \;
 
Old 07-31-2009, 01:29 PM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by repo View Post
Try

Code:
find / -name .AppleD* -exec /bin/rm {} \;
<pedantic mode>Safer
Code:
find / -name '.AppleD*' -exec /bin/rm {} \;
<\pedantic mode>
 
Old 07-31-2009, 01:33 PM   #7
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Quote:
Originally Posted by repo View Post
Try

Code:
find / -name .AppleD* -exec /bin/rm {} \;
You have to escape the * or quote it otherwise the shell expands it before it's passed to find:
Code:
find / -name ".AppleD*" -exec /bin/rm {} +
The + at the end is quicker than the \;, which launches an instance of rm for every file found; the + meanwhile passes a bunch of files as arguments to a single rm, thus reducing the number of instances of rm called.
 
Old 07-31-2009, 11:01 PM   #8
Iyyappan
Member
 
Registered: Dec 2008
Location: Chennai, India
Distribution: CentOS 5, SLES 11
Posts: 235

Original Poster
Rep: Reputation: 4
Reg :Scripts

thanx a lto everybody...
 
Old 08-02-2009, 07:40 AM   #9
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by pwc101 View Post
You have to escape the * or quote it otherwise the shell expands it before it's passed to find:[code]
Yes, somehow you have to pass .AppleD* to find without bash doing file name expansion on it first. There are 4 ways you can do that:
  1. Single quotes: '.AppleD*'.
  2. Double quotes: ".AppleD*". Bash will expand some things in double quotes -- will be a problem if, for example the pattern includes a $. You could escape these but that's making things unnecessarily complex. So the single quotes are safer, simpler (and faster).
  3. Escape any characters in the pattern that are meaningful for file name expansion: .AppleD\*
  4. Turn off file name expansion: shopt -f; find <stuff> -name .AppleD*
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Slackbuild files in /tmp. Ok to delete? Romanus81 Slackware 9 11-05-2008 10:45 PM
Unable to delete files in /tmp/kdecache : Input/output error wurzeld Linux - Newbie 2 10-28-2008 03:24 PM
Script help - delete files older than 45 days but exclude the system files jojothedogboy Linux - Software 3 06-13-2008 04:43 PM
How To Delete tmp Files In FC5 zenarcher Fedora 3 09-07-2006 01:51 AM
can i delete /tmp files? demmylls Linux - General 1 03-01-2004 11:14 AM


All times are GMT -5. The time now is 02:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration