If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Create a script to find and delete files question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-16-10, 08:05
conormd7 conormd7 is offline
Registered User
 
Join Date: Dec 2010
Location: Ireland
Posts: 1
Create a script to find and delete files question

I use the extension .tmp do show temporary files. However, these files could be in any one of several folders. Create a script to find and delete these.
This is a question i have for college and cannot do it. Does anyone know how to do it. Thanks!
Reply With Quote
  #2 (permalink)  
Old 12-16-10, 11:25
kitaman kitaman is offline
Papabi's friend
 
Join Date: Sep 2009
Location: Ontario
Posts: 629
Look at the 'find' command. It will search directories for files that meet a variety of criteria.
for your particular instance use:
Code:
find ./ -name "*.tmp"
Reply With Quote
  #3 (permalink)  
Old 12-17-10, 10:45
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Wink

Quote:
Originally Posted by kitaman View Post
Look at the 'find' command. It will search directories for files that meet a variety of criteria.
for your particular instance use:
Code:
find ./ -name "*.tmp"
And...check out the "-exec" option of the find command to add the command to remove the files.
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #4 (permalink)  
Old 12-18-10, 17:41
spacebar spacebar is offline
Registered User
 
Join Date: Feb 2006
Posts: 73
Create list of files with extension '*.tmp' to a file:
Code:
find / -type f -name '*.tmp' -print 2>>/dev/null > /tmp/tmp_files_list.txt


Review and validate you are sure you want to delete files and if necessary edit file to remove any file names you do not want to delete:
Code:
less /tmp/tmp_files_list.txt


Remove files:
Code:
for file in $(</tmp/tmp_files_list.txt)
  do
    rm $file
  done


hth
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On