LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   script to delete tmp files (https://www.linuxquestions.org/questions/linux-newbie-8/script-to-delete-tmp-files-743951/)

Iyyappan 07-30-2009 12:04 PM

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.....

repo 07-30-2009 12:10 PM

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 {} \;

centosboy 07-31-2009 03:36 AM

Code:

find /directory/of/temp/files -name '*.tmp' -delete

Iyyappan 07-31-2009 12:14 PM

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.........

repo 07-31-2009 12:19 PM

Try

Code:

find / -name .AppleD* -exec /bin/rm {} \;

catkin 07-31-2009 12:29 PM

Quote:

Originally Posted by repo (Post 3626835)
Try

Code:

find / -name .AppleD* -exec /bin/rm {} \;

<pedantic mode>Safer
Code:

find / -name '.AppleD*' -exec /bin/rm {} \;
<\pedantic mode>

pwc101 07-31-2009 12:33 PM

Quote:

Originally Posted by repo (Post 3626835)
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.

Iyyappan 07-31-2009 10:01 PM

Reg :Scripts
 
thanx a lto everybody...

catkin 08-02-2009 06:40 AM

Quote:

Originally Posted by pwc101 (Post 3626854)
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*


All times are GMT -5. The time now is 12:03 PM.