The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
remove empty directory sirrtuan Shell Programming and Scripting 7 04-09-2009 12:41 AM
Transfer files wih directory structure. uxlunatick SCO 11 04-28-2008 03:25 PM
copy files with directory structure adddy UNIX for Dummies Questions & Answers 3 12-11-2006 08:50 AM
MV files from one directory structure(multiple level) to other directory structure srmadab UNIX for Advanced & Expert Users 4 09-13-2006 04:01 PM
disk space used for files with in a directory structure. kasala Shell Programming and Scripting 8 01-14-2005 04:26 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-05-2008
cat123 cat123 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 3
Script to remove all empty files within the directory structure?

Hi I need to write a shell script which basically searches for all the empty files within the directory structure, lists them before asking the user to confirm if they would like to delete them. If the user deletes the file then a notice would appear confirming the file is deleted.

I've be trying to do this for weeks now and its driving me mad, I'm quite new to this, although I am getting to grips with it slowly.

Cheers
  #2 (permalink)  
Old 06-05-2008
subin_bala subin_bala is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 57
use the following command to identify the empty files in ur directory

find . -name "*.*" -size 0c
  #3 (permalink)  
Old 06-05-2008
cat123 cat123 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 3
Cool

Thanks for the reply m8.

I don't think I explained what I was trying to do correctly, I'm trying to create a shell script that will allow me to find all empty files within my directory tree, list them and then give me the option of deleting them. I would like to be able to get the option of deleting them in the format of :

delete word.doc y/n? :> y
word.doc deleted.

I know some files that are empty are not to be deleted this is why I need to see what I am about to get rid of.

I'm just strating out doing Linux and I've hit a brick wall with this so any help would be appreciated, cheers.

Last edited by cat123; 06-05-2008 at 06:56 AM..
  #4 (permalink)  
Old 06-05-2008
nua7 nua7 is offline
Registered User
  
 

Join Date: Mar 2008
Location: /bin/sh
Posts: 353
This pseudo code may put you on right lines...

Code:
file_names=`find . -name "*.*" -size 0c`
for i in $file_names
do
print "Do you want to delete the file?"
read input
if ans='y' or 'Y'
rm -f $i
else 
#do nothing
echo "File not deleted"
fi
done
  #5 (permalink)  
Old 06-05-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,257
You can also use
Code:
find . -name "*.*" -size 0c -exec rm -i {} \;
"rm -i" asks you if you want to delete it or not. Works on Debian Linux and AIX at least.

Btw. that find did not work for me on Debian and AIX. If you encounter the same problem, you might try:
Code:
find . -type f -size -1 -exec rm -i {} \;
  #6 (permalink)  
Old 06-05-2008
cat123 cat123 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 3
cheers guys for the help, im gonna give it a go and I'll let you's know how I do.

Cheers
Sponsored Links
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 01:49 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0