Visit Our UNIX and Linux User Community


Script for Deleting Core files on root filesystem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script for Deleting Core files on root filesystem
# 1  
Old 02-11-2008
Script for Deleting Core files on root filesystem

ok i am setting up a script to run daily using crontab. This script will search the root filesystem and delete any and all core files. I have set up this script

Quote:
find / -name core -exec rm -f {} \;
The only problem i get with this script is it searches for directories and attempts to delete them. Since i have probably 100-200 directories(not by my creation) with the name core(driver files mainly) i do not want to be spammed with a hugh list of directories that cannot be deleted. Is there a way i can fix up this script so it only looks for files and ignores all directories?

BTW this job has to be finished by 1800 hours today. Thank you for all the help you can provide

Last edited by rgfirefly24; 02-11-2008 at 06:08 PM..
# 2  
Old 02-11-2008
try to add the option -prune
Code:
find / -name core -prune -exec rm -f {} \;

# 3  
Old 02-11-2008
ok i tried the code as you have it, however it still comes up saying rm : cannot remove '<directory path>' : is a directory
# 4  
Old 02-11-2008
to look only for files use: -type f
Code:
find / -name core -type f -prune -exec rm -f {} \;

# 5  
Old 02-11-2008
ok thanks ynixon with the -type f on it the script works perfectly. Next questions is: is there a way to send an output to file of the files that were deleted?
# 6  
Old 02-11-2008
you can use the following command before actually deleting
Code:
find / -name core -type f -prune -print

# 7  
Old 02-11-2008
will that send it to a file or to the printer?

(i know lpr and lp are the print commands; however, i have never used -print before.)

Previous Thread | Next Thread
Test Your Knowledge in Computers #729
Difficulty: Medium
BASIC stands for Basic All-purpose Symbolic Instruction Code.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script for deleting Files

Hello, I am new to shell scripting..i need your help. i have the delete the log files which are present in the specific path .i have the rules as below. 1)In Path1 i need to delete all the files which are present 2)in Path2 i need to keep 1 month of data and delete the rest of the data... (5 Replies)
Discussion started by: rajesh25
5 Replies

2. UNIX for Dummies Questions & Answers

Script for Monitoring Root Filesystem

I am on SCO UNIX, I need to write a script to monitor root file system. For some reason it's not working for me. #!/bin/sh df -B / | awk '{ print $5 " " $1 }' | while read output; do echo $output if ; then echo "Running out of space \ HOSTNAME" # mail -s "Alert: Almost out of... (8 Replies)
Discussion started by: samnyc
8 Replies

3. Shell Programming and Scripting

Bash script deleting my files, and editing files in subdirectories question

#!/bin/bash # name=$1 type=$2 number=1 for file in ./** do if then filenumber=00$number elif then filenumber=0$number fi tempname="$name""$filenumber"."$type" if (4 Replies)
Discussion started by: TheGreatGizmo
4 Replies

4. UNIX for Dummies Questions & Answers

find large files in root filesystem and exclude others

I am wondering if there is a way to search for top 10 files in size in root filesystem but exclude all other mounts including nfs mounts . For example excluded /var /boot /app /app1 /u01/ (1 Reply)
Discussion started by: gubbu
1 Replies

5. HP-UX

[Solved] Deleting a all core files present in file systems ?

Hi All IN HPUX 11 How to delete an unwanted "core" file with a single command which is being generated in different locations of the system the command should be able to free up the space occupied by all "core" file which is present in different folders and filesytems in a system ... (5 Replies)
Discussion started by: sidharthmellam
5 Replies

6. Solaris

Root Filesystem

Hi, Can we install root file system on other than 0th slice???? (5 Replies)
Discussion started by: tirupathiraju_t
5 Replies

7. Shell Programming and Scripting

Script for Deleting files

Hi All, I need a script which compares the sysdate and the file date(Last updated time stamp) and if the time difference is greater than 10 mins i need to delete that file. Can anyone help me pls?????? Ashok. (5 Replies)
Discussion started by: Ashok_oct22
5 Replies

8. UNIX for Dummies Questions & Answers

Deleting core file??

Hi, I am using UNIX through Exceed on my PC to gain access to some CFD programs. One of these programs crashed a couple of days ago and created a file called core, which i understand is a back up file and can be deleted immediately. However, before deleting it I rearranged some of my other files... (1 Reply)
Discussion started by: alc640
1 Replies

9. Shell Programming and Scripting

Deleting root files from another user

I want to delete some files and directories owned by root from another different user in HP-UX 10.20. The list of files looks like: (user test) bash-2.03$ ls -alrt total 20 ... (2 Replies)
Discussion started by: choo
2 Replies

Featured Tech Videos